nginx + php-fpm = 找不到文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24208139/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
nginx + php-fpm = File not found
提问by user3652969
When i try accessing info.php
I get a File not found.
error.
当我尝试访问时info.php
出现File not found.
错误。
I tried some Tutorials to no avail.
我尝试了一些教程无济于事。
Configs: default:
配置:默认:
server {
listen 80;
listen [::]:80 default ipv6only=on;
server_name localhost;
location / {
root /var/www;
index index.html index.htm index.php;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_pass 127.0.0.1:7777;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
fastcgi_buffers 256 128k;
#fastcgi_buffer_size 16k;
#fastcgi_busy_buffers_size 256k;
fastcgi_connect_timeout 300s;
fastcgi_send_timeout 300s;
fastcgi_read_timeout 300s;
include fastcgi_params;
}
}
What's the problem?
有什么问题?
回答by ffflabs
If that info.php is in /var/www, then it's wrong to instruct fast_cgi to look for
如果那个 info.php 在 /var/www 中,那么指示 fast_cgi 查找是错误的
/usr/share/nginx/html/info.php;
Use the same root for html and php. Also, root
and index
parameters should be outside a particular location except for very specific uses.
对 html 和 php 使用相同的根。此外,除了非常特定的用途外root
,index
参数应该在特定位置之外。
server {
listen 80;
listen [::]:80 default ipv6only=on;
server_name localhost;
root /var/www;
index index.html index.htm index.php;
#pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
fastcgi_pass 127.0.0.1:7777;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_buffers 256 128k;
fastcgi_connect_timeout 300s;
fastcgi_send_timeout 300s;
fastcgi_read_timeout 300s;
include fastcgi_params;
}
}
needless to say, you still need to make sure your php-fpm service is listening at port 7777. Common case is to have it listening at port 9000.
不用说,您仍然需要确保您的 php-fpm 服务正在侦听端口 7777。常见情况是让它侦听端口 9000。
回答by Nazir
If you checked every thing and it's correct configured, then there is last point i got:
如果您检查了所有内容并且配置正确,那么我得到的最后一点是:
- check that correct username if mentioned in file
/etc/php-fpm.d/www.conf
- 如果在文件中提到,请检查正确的用户名
/etc/php-fpm.d/www.conf
回答by zy chen
server {
listen 80;
listen [::]:80 default ipv6only=on;
server_name localhost;
root /var/www;
location / {
index index.php;
}
location ~ \.php(?:$|/) {
fastcgi_pass 127.0.0.1:7777;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_buffers 256 128k;
fastcgi_connect_timeout 300s;
fastcgi_send_timeout 300s;
fastcgi_read_timeout 300s;
include fastcgi_params;
}
}
}
回答by Jonathan
Nginx & Symlinks
Nginx 和符号链接
Note, if root /var/www;
is a symlink, change it to root /var/www/;
otherwise nginx won't go past the symlink and you'll get a File not found
error
请注意,如果root /var/www;
是符号链接,请将其更改为root /var/www/;
否则 nginx 不会通过符号链接,并且您会收到File not found
错误消息
回答by Joshua Walsh
I had this issue and none of the answers here worked. The issue for me ended up being caused by SELinux. I disabled SELinuxand it fixed the issue.
我遇到了这个问题,这里的答案都没有奏效。我的问题最终是由 SELinux 引起的。我禁用了 SELinux,它解决了这个问题。
Be aware that disabling SELinux does have an impact on security. There's almost certainly a better way to fix this, but disabling SELinux works for my purposes.
请注意,禁用 SELinux 确实会影响安全性。几乎可以肯定有更好的方法来解决这个问题,但禁用 SELinux 对我有用。
回答by Oliver Jenkins
I came across this whilst trying to solve a similar problem. So I'll add the solution I found when I got to it. This was on Arch, but it is systemd related.
我在尝试解决类似问题时遇到了这个问题。所以我会添加我找到的解决方案。这是在 Arch 上,但它与 systemd 相关。
This solution is for my development machine, and for good reasons, you shouldn't run a public site from your /home folder.
此解决方案适用于我的开发机器,出于充分的理由,您不应从 /home 文件夹运行公共站点。
I configured php-fpm and nginx to run as my user. Edit the following file, and remove the ProtectHome=true line
我将 php-fpm 和 nginx 配置为以我的用户身份运行。编辑以下文件,并删除 ProtectHome=true 行
sudo vi /etc/systemd/system/multi-user.target.wants/php-fpm.service
Reload, and restart everything;
重新加载,并重新启动一切;
systemctl daemon-reload
systemctl restart nginx.service
systemctl restart php-fpm.service
回答by Michiel Auerbach
I took a long look at this, in the end turned out that FPM wasn't running :-s in my case a simple service php7.2-fpm restart did the trick!
我看了很久,最后发现 FPM 没有运行 :-s 在我的情况下,一个简单的服务 php7.2-fpm restart 就成功了!