我正在尝试使用 nginx 为 PHP 提供服务,我已经关注了 this tutorial之前成功但由于某种原因在新服务器上我收到以下错误:
nginx: [emerg] open() "/etc/nginx/snippets/fastcgi-php.conf" failed (2: No such file or directory)
事实上,nginx 安装的整个snippets
目录都不见了。
我已经使用以下命令安装了 PHP:
- sudo apt-get install -y php7.0-cli php7.0-cgi php-fpm php-mysql
- sudo systemctl restart php7.0-fpm
我已经安装了可用的最新 nginx - 但目录和文件仍然不存在。
如何解决这个问题?
奖金:可能是什么原因造成的?
最佳答案
简单描述:
最终版本是:
location ~ \.php$ {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
}
我认为这取决于您使用的 Nginx 版本。
对于 Nate 的回答,nginx-full
将为您安装 1.10.3。
我在 Ubuntu 16.04 上使用 Nginx 1.12.2,这个版本没有 sites-enabled
和 sites-available
;它还有一个不同的 PHP CGI 设置。
您可以使用 Ulad Kasach 的解决方案,也可以开始使用新方法。
这是一个关于如何操作的官方文档:https://www.nginx.com/resources/wiki/start/topics/recipes/wordpress/
顺便说一句,在上面的帖子中,您还应该将 fastcgi.conf
替换为 fastcgi_params
。
然后再添加一行,原来是默认的:
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
这些都是 Nginx 1.12.2 的新变化:(
最终版本是:
location ~ \.php$ {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
}
关于php - Nginx 的 fastcgi-php.conf 片段丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43262435/