nginx - 索引和根页面不工作,502 Bad Gateway

标签 nginx

网址 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
    

    理想的是通用套接字,即 php-fpm.sock ,但似乎不一样(不是重定向到 php7.4-fpm.sock ?)。

    最佳答案

    Ideal 是一个通用套接字,但现在使用的是 php7.4-fpm.sock :

    server {
            server_name example.org example.com;
            ...
            location ~ \.php$ {
              include snippets/fastcgi-php.conf;
              fastcgi_pass unix:/run/php/php7.4-fpm.sock;
            }
    }
    

    这个解决方案并不完美(PHP 更改版本时的大问题)但工作正常。

    关于nginx - 索引和根页面不工作,502 Bad Gateway,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62407367/

    相关文章:

    caching - Nginx 内容缓存导致 Docker 内存峰值

    Heroku Cedar和Nginx(gzip)

    php - 如何减少 TTFB(到第一个字节的时间)响应?

    node.js - 是否可以让上游服务器在 Nginx 服务器后面处理 SSL 证书?

    nginx - 为什么忽略 nginx my "auth_basic off"的子路径位置指令?

    php - Nginx 重写 CodeIgniter 应用程序主 CodeIgniter 应用程序子目录中的配置

    nginx - HTTP 1.0 请求是否在 play 框架 2.2.1 中提供分块响应

    authentication - nginx auth_request : access original query parameter

    nginx - 为什么 gzip_disable 会使 nginx 崩溃?

    nginx - 代理服务返回 HTTP 202 时的反向代理