php - Nginx 的 fastcgi-php.conf 片段丢失

标签 php ubuntu nginx

我正在尝试使用 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-enabledsites-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/

相关文章:

php - 如何调试似乎没有运行的 PHP CRON 脚本?

php - 关键字 highlight 是在 PHP preg_replace() 中高亮显示高亮

php - 从数据中提取 JSON 数组

QT Creator,编译和部署一个c或c++到远程设备(BeagleBone或R pi)

r - 如何安装和管理多个版本的 R 包

php - Eclipse PDT 中的 xDebug 观察点?

javascript - 错误:当没有进程使用 8080 端口时监听 EADDRINUSE:::8080

apache - 如何使用托管在 Ubuntu 中的 nginx 在 docker 中启用 SSL

php - Github 身份验证失败,用户 www-data

mysql - 使用正在运行的 nginx 代理在 docker 中运行 Teampass