【问题标题】:Nginx throw 502 bad gateway on php5-fpm setupNginx 在 php5-fpm 设置上抛出 502 bad gateway
【发布时间】:2014-10-17 10:08:03
【问题描述】:

这是我的设置细节

Nginx.conf

user  nginx;
worker_processes  8;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  4096;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;


    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

}

我的 conf 文件,文件名默认位于可用站点和已启用站点中

server {
    server_name www.subdomain.mywebsite.com subdomain.mywebsite.com;
    access_log /srv/www/subdomain.mywebsite.com/logs/access.log;
    error_log /srv/www/subdomain.mywebsite.com/logs/error.log;
    root /srv/www/subdomain.mywebsite.com/public_html;

    location / {

        index index.html index.htm index.php;
    }


    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param SCRIPT_FILENAME /srv/www/subdomain.mywebsite.com/public_html$fastcgi_script_name;
    }
}

当我通过我的域运行 html 文件时,它工作正常。

但是如果我去php文件,比如例子

subdomain.mywebsite.com/info.php

它给出了 nginx 的 502 bad gateway 错误

出现问题时,Php5-fpm 正在运行

root@ubuntu:/etc/nginx/sites-available# service php5-fpm status
php5-fpm start/running, process 12196

【问题讨论】:

  • 您是否尝试过通过套接字连接到 PHP-FPM?比如:fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
  • @ajtrichards_wales 我试过了,同样的 502 badgateway

标签: nginx php


【解决方案1】:

这是典型响应的工作方式:向 Nginx 发送请求,Nginx 代表客户端浏览器将该请求发送到 PHP-FPM; PHP-FPM 使用其评估代码进行响应,然后将该响应发送回 Nginx。在您的情况下,这种情况仍在发生。问题是 PHP-FPM 没有发送你想要的结果。您希望对代码进行评估,但它表示它或多或少无法读取代码,因此它告诉 Nginx 它没有出错,因此 Nginx 告诉客户端浏览器“网关”(上游服务器,是 PHP -FPM) 是个混蛋;也就是说,它会向客户端浏览器发送 502 响应,因为它不能空手而归。

这是什么意思?

不出所料,这意味着权限是错误的。权限正在阻止 PHP-FPM 做它的事情。找到 PHP-FPM 的 www.conf 文件,并调整 listen.owner、listen.group、listen.mode、user 和 group 设置。另外,只需使用套接字。这是在同一个地方配置的。实际上,我刚刚列出的权限设置仅适用于套接字。尽管如此,如果你想在监听端口上继续运行 Nginx,这仍然是一个权限问题。

您的日志很容易说明这一点。你真的调查过这个问题吗?搜索引擎可能会被与此信息相关的结果淹没。

【讨论】:

    猜你喜欢
    • 2019-12-17
    • 1970-01-01
    • 2018-11-12
    • 2020-08-01
    • 1970-01-01
    • 2017-05-03
    • 2018-09-12
    • 2017-12-30
    • 1970-01-01
    相关资源
    最近更新 更多