我正在尝试使用nginx提供PHP服务,我之前已经成功地使用了本教程,但出于某种原因我在新服务器上遇到以下错误:
nginx: [emerg] open() "/etc/nginx/snippets/fastcgi-php.conf" failed (2: No such file or directory)
Run Code Online (Sandbox Code Playgroud)
实际上,snippets
缺少nginx安装的整个目录.
我用以下命令安装了PHP:
- sudo apt-get install -y php7.0-cli php7.0-cgi php-fpm php-mysql
-sudo systemctl restart php7.0-fpm
我已经安装了最新的nginx,但目录和文件仍然不存在.
如何解决这个问题?
奖金:可能是什么导致了这个?
Yan*_*333 19
我认为这取决于你使用的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
.
并添加一个默认为orignially的行:
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;
}
Run Code Online (Sandbox Code Playgroud)
最终不得不查看先前的有效配置文件并手动复制它。只需创建snippets
目录并添加fastcgi-php.conf
具有以下内容的文件:
# regex to split $uri to $fastcgi_script_name and $fastcgi_path
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# Check that the PHP script exists before passing it
try_files $fastcgi_script_name =404;
# Bypass the fact that try_files resets $fastcgi_path_info
# see: http://trac.nginx.org/nginx/ticket/321
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
fastcgi_index index.php;
include fastcgi.conf;
Run Code Online (Sandbox Code Playgroud)
您还需要更换的最后一行,include fastcgi.conf;
用include fastcgi_params;
。
我建议创建一个文件,fastcgi.conf;
如果它实际上不是同一文件,则fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
在以下情况下需要附加一行:fastcgi.conf
小智 5
我在用
我的网站配置看起来像这样
server {
listen 3010;
root /usr/share/nginx/docs;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name phpSetup;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
Run Code Online (Sandbox Code Playgroud)
并且工作得很好。所以我建议更新您的配置, 包括代码段/fastcgi-php.conf; 到
包括 fastcgi_params;
所以位置块是
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
Run Code Online (Sandbox Code Playgroud)
希望能帮助到你
阅读更多内容:https : //www.nginx.com/resources/wiki/start/topics/recipes/wordpress/
谢谢,
归档时间: |
|
查看次数: |
20498 次 |
最近记录: |