【发布时间】:2020-07-02 16:41:20
【问题描述】:
URL example.org/index.php(和任何example.org/etc.php)失败,但example.org/foo 工作正常,适用于任何foo 文件夹。
server {
server_name example.org example.com;
access_log /var/log/nginx/example.org.access_log;
root /var/www/example.org/;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =403;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
- nginx 版本:
1.17.10(Ubuntu) - ?
/var/log/nginx/error.log(没有特定于服务器?)
sudo tail /var/log/nginx/error.log 什么都不显示,只显示其他站点的错误,
...
2020/06/19 12:58:02 [error] 871296#871296: *23 "/var/www/example2.org/index2.php" is not found (2: No such file or directory), client: 181.177.112.xx, server: example2.org, request: "GET / HTTP/1.0", host: "example2.org"
解决方案的主要线索(见我的回答)
文件/run/php/php7.0-fpm.sock不存在,所以失败在fastcgi_pass unix:/run/php/php7.0-fpm.sock;。
ls -l /run/php/*.sock 显示
lrwxrwxrwx 1 root root 30 May 17 05:18 /run/php/php-fpm.sock -> /etc/alternatives/php-fpm.sock
srw-rw---- 1 www-data www-data 0 May 29 06:40 /run/php/php7.4-fpm.sock
Ideal 是一个通用套接字,即php-fpm.sock,但它似乎不一样(不重定向到php7.4-fpm.sock?)。
【问题讨论】:
-
每个
server {}块都应该有一个listen。例如:listen 80;或listen 443 -
嗨@0stone0,没有意义,正如我在问题中所说,它适用于
/foo文件夹:listen错误会影响文件夹和根 URL。listen 80在/etc/nginx/sites-available/default原始 NGINX 脚本上,看起来工作正常 -
您可以发布一些来自 error.log 和 /var/log/nginx/example.org.access_log 的日志吗?
-
嗨@DilsonRainov,文件
access_log在那里,没有相关信息进入,但是error.log 在哪里? 是通用/var/log/nginx/error.log还是有一个特定于域? -
好的。你能 ls 文件 /run/php/php7.0-fpm.sock 吗?看起来 php-fpm 没有启动。
标签: nginx