2016-04-28 28 views
0

私のウェブサイトでうまくいくはずのURLパターンがあります。Yii2 URL書き換えサフィックス(PHP)の問題

[ 
'pattern'=>'page/result', 
'route'=>'site/index', 
'suffix'=>'.html' 
], 
[ 
'pattern'=>'page/result', 
'route'=>'site/index', 
'suffix'=>'.php' 
], 

これらの2つのURLサフィックス.htmlは正常に動作していますが、.phpサフィックスはMY Nginx Serverでは機能しません。また、私のサイトのnginx設定を確認してください。 (動作しない)(作業)

server { 


listen 8081 default_server; 
    listen [::]:8081 default_server; 

    root /var/www/html/yii2project/frontend/web; 

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


    access_log /var/log/yii2/access.log; 
    error_log /var/log/yii2/error.log; 

    server_name yii2.local; 

    location/{ 
     # First attempt to serve request as file, then 
     # as directory, then fall back to displaying a 404. 
     #try_files $uri $uri/ =404; 
      root /var/www/html/yii2/frontend/web; 
      index index.html index.htm index.php; 
      try_files $uri $uri/ /index.php?$args;#now 
      #rewrite ^/(.*)$ /$1 last; 
      #if ($http_host ~* "^yii2.local:8081"){ 
      #rewrite ^(.*)$ http://www.yii2.local:8081$1 redirect; 
      #} 

     } 

     #caching of static files 
     location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ { 
      expires 365d; 
     } 


    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
    # 
    location ~ \.php$ { 
    # include snippets/fastcgi-php.conf; 
       fastcgi_split_path_info ^(.+\.php)(/.+)$; 
    # 
    # # With php5-cgi alone: 
    # fastcgi_pass 127.0.0.1:9000; 
    # # With php5-fpm: 
     fastcgi_pass unix:/var/run/php5-fpm.sock; 
     fastcgi_index index.php; 
     include /etc/nginx/fastcgi_params; 
       fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;    # include fastcgi.conf; 
       include fastcgi.conf;#now 
     fastcgi_read_timeout 300;  

    } 
} 

http://yii2.local:8081/page/result.html http://yii2.local:8081/page/result.php

nginxの設定を参照してくださいと私は間違っconfigurartionだところを教えてください。

答えて

0

あなたは少し奇妙に思える三つの異なるドキュメントルートしている:

/var/www/html/yii2project/frontend/web 
/var/www/html/yii2/frontend/web 
/usr/share/nginx/html 

最初はリソースファイル(.css.js)を見つけるために使用されます。 2番目のファイルは.html個のファイルの検索に使用されます。 3番目はファイル.phpの検索に使用されます。

すべてのファイルが共通のルートを共有すると仮定すると、serverブロックでrootディレクティブを配置し、すべてのlocationブロックが値を継承できるようにすることが通常です。

おそらく最初のディレクティブの値を変更する必要があります。 location /ブロックのrootディレクティブを削除し、SCRIPT_FILENAMEの定義を変更します。誤解によって

server { 
    ... 
    root /var/www/html/yii2/frontend/web; 
    ... 
    location/{ ... } 
    location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ { ... } 
    location ~ \.php$ { 
     ... 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    } 
} 
+0

I書き込み/ var/www/htmlと設定/ yii2project /フロントエンド/ウェブ私のルート・パスは、この/ var/www/htmlと設定/ yii2 /フロントエンド/ウェブであると私は8081ポートでApacheとnginxのを使用していますだからnginxサイト - 利用可能なデフォルトのファイルでは、nginxサーバーで1つのプロジェクトだけを設定します。また、fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_nameを変更してください。それが機能しない。 – truesource