Nginx 將.php 檔案作為下載而不是執行它們
在這種情況下,Nginx 錯誤地處理.php 文件,下載它們而不是執行它們執行他們。若要修正此問題,必須進行某些配置調整。
1.取消註解監聽行:
修改/etc/nginx/sites-available/default 以啟用Nginx 監聽IPv4 和IPv6 埠80:
listen 80; ## listen for ipv4; listen [::]:80 default_server ipv6only=on; ## listen for ipv6
2 。設定伺服器名稱:
確保 server_name 反映實際的伺服器名稱,例如 server_name example.com;.
3.將index.php加入索引行:
在根指令中,將index.php加入索引檔清單:
root /var/www/html; index index.php index.html index.htm;
4.取消註解PHP Location區塊:
取消註解location ~ .php$ {} 區塊以啟用PHP 處理:
location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+?\.php)(/.+)?$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; }
5.在php.ini 中停用Pathinfo Fix:
編輯/etc/php5/fpm/php.ini 並設定cgi.fix_pathinfo = 0。
6.重啟 Nginx 和 PHP-FPM:
重啟 Nginx 和PHP-FPM:
sudo service nginx restart && sudo service php5-fpm restart
修改設定:
server { listen 80; listen [::]:80 default_server ipv6only=on; root /var/www/html; index index.php index.html index.htm; # Make site accessible from http://example.com/ server_name example.com; location ~ \.php$ { try_files $uri $uri/ =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini # # # 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 fastcgi_params; } location / { try_files $uri $uri/ =404; # Uncomment to enable naxsi on this location # include /etc/nginx/naxsi.rules }
實作這些變更後,Nginx 應該正確執行 .php 檔案。
以上是為什麼 Nginx 下載 .php 檔案而不是執行它們,我該如何修復它?的詳細內容。更多資訊請關注PHP中文網其他相關文章!