[英]NGINX downloads php file
我有自己的MVC,其中包含許多具有此文件夾結構的應用程序:
apache一切正常。 我想使用Nginx嘗試它,但是當我在瀏覽器中訪問它時,它會下載index.php,但它不執行它。
這是我在nginx上的設置:
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
# try_files $uri $uri/ =404;
if (!-e $request_filename){ rewrite ^(.*)$ /index.php?rt=$1 break; }
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ .php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
兩行:
if (!-e $request_filename){ rewrite ^(.*)$ /index.php?rt=$1 break; }
try_files $uri $uri/ /index.php$is_args$args;
試圖執行相同的功能。 如果文件不存在,請嘗試/index.php
。
第一行由於break
失敗,它嘗試在location /
塊而不是location ~ \\.php$
塊中處理/index.php
。
要更正第一行,應使用last
而不是break
。 有關詳細信息,請參見此文檔 。
但是,如果包含try_files
行,則不需要if ... rewrite
語句。 以下執行類似的功能:
try_files $uri $uri/ /index.php?rt=$uri&$args;
我更喜歡try_files
方法,但是任何一種都可以,但是您不需要兩者。 try_files
在此處記錄 。 請注意在使用if
塊時的注意事項 。
另外,請注意您location ~ \\.php$
某些問題location ~ \\.php$
塊:
try_files
指令應以URI或= 404結尾-不能同時
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.