Nginx 以下载方式提供 PHP 文件:解决执行问题
当遇到 Nginx 以下载方式提供 PHP 文件而不是执行它们的情况时,诊断根本原因至关重要。
检查配置文件:
配置示例:
server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; root /var/www/html; index index.php index.html index.htm; # Make site accessible from http://localhost/ server_name localhost; location ~ \.php$ { try_files $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 和 php5-fpm:
sudo service nginx restart sudo service php5-fpm restart
额外注意事项:
以上是为什么 Nginx 将我的 PHP 文件作为下载而不是执行它们?的详细内容。更多信息请关注PHP中文网其他相关文章!