2017-05-22 14 views
0

後にURLの最初のセグメントに基づいて動的にnginxの「インデックス」を変更することが可能である:、/var/www/htmlと設定/公衆それは私がnginxのファイルにルートを設定したドメインアドレス

私のドメインは一例です。 com。

私は example.com/first を入力した場合、それは/var/www/html/public/first.phpファイルを実行することを実現したいです。

私はexample.com/secondを入力した場合、それは/var/www/html/public/second.phpを実行します。私はexample.com/thirdを入力した場合

それは、/var/www/html/public/third.phpを実行します。

でも可能ですか?

+1

ここで "エクステンデッドのPHP"を検索することができます - 多くの解決策があります。 –

+0

@リチャードスミスありがとう:) – Dominik

答えて

0

@リチャード・スミスは、彼のアドバイスによって私に大きな支持を与えてくれました。私は拡張機能のないphpを検索しています。誰もがこれまで私のようにこれを知っているわけではありません。

server { 
    listen 80; 

    root /vagrant/public; 

    # Add index.php to the list if you are using PHP 
    index index.php index.html index.htm; 

    server_name your_domain_name; #for example example.com 

    location/{ 
     try_files $uri $uri/ @extensionless-php; 
     index index.php index.html; 
    } 
    location @extensionless-php { 
     rewrite ^(.*)$ $1.php last; 
    } 

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
    # You must use this, because if You not use it, You will get surce code instead of result of php script execution. 
    location ~ \.php(/|$) { 
     fastcgi_pass unix:/run/php/php7.0-fpm.sock; 
     fastcgi_split_path_info ^(.+\.php)(/.*)$; 
      include fastcgi_params; 
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    } 
} 
関連する問題