使用nginx的任何php文件均出现404错误 [英] 404 error with any php file, using nginx
问题描述
我知道这个问题已经被问过无数次了,尽管我已经尝试了各种解决方案,但许多建议都表明我还没有解决我的问题:
I realize this question has been asked numerous times, yet despite all my attempts to put in place the various solutions many have suggested I have yet to solve my problem:
无论我做什么,我网站上的任何php文件都给我404错误. html文件可以正常工作.
no matter what I do, any php file on my website gives me a 404 error. html files work perfectly, however.
我的nginx.conf:
my nginx.conf:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POOD$
ssl_prefer_server_ciphers on;
access_log /home/****/websites/logs/access.log;
error_log /home/****/websites/logs/error.log;
include v-hosts/*.conf;
#### prevent processing requests with undefined server names
server {
listen 80;
server_name '';
return 444;
}
}
我的/etc/nginx/v-hosts/website.com.conf
my /etc/nginx/v-hosts/website.com.conf
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /home/*****/websites/website.com/root;
index index.php index.html index.htm;
server_name website.com www.website.com;
location / {
try_files $uri $uri/ =404;
root /home/****/websites/website.com/root;
index index.php index.html index.html;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /home/****/websites/website.com/root;
}
location ~ \.php$ {
root /home/****/websites/website.com/root;
try_files $uri =404;
fastcgi_pass unix:/run/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
}
}
- 我已经在 php.ini 中设置了
- 我在/home/****/websites/website.com/root 中有一个 index.php 和一个 info.php
- I have set
cgi.fix_pathinfo=0
in php.ini - I have an index.php as well as an info.php in /home/****/websites/website.com/root
cgi.fix_pathinfo=0
谢谢
推荐答案
我已经成功解决了我的问题!访问/home/****/websites/logs/error.log中的错误日志后,我意识到我的路径fastcgi_pass unix:/run/php7.0-fpm.sock;
是错误的.我已将其更改为fastcgi_pass unix:/run/php/php7.0-fpm.sock;
,现在页面可以正确显示!
I have successfully fixed my issue! after accessing the error log in /home/****/websites/logs/error.log , I realized my path fastcgi_pass unix:/run/php7.0-fpm.sock;
was wrong. I have changed it to fastcgi_pass unix:/run/php/php7.0-fpm.sock;
and the page now displays correctly!
`
这篇关于使用nginx的任何php文件均出现404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!