【问题标题】:nginx show 502 bad gatewaynginx 显示 502 错误网关
【发布时间】:2020-03-19 12:08:07
【问题描述】:

502 网关错误。 错误日志和nginx配置如下。 这有什么问题吗?

[error] 7660#0: *10 connect() failed (111: Connection refused) while 连接上游,客户端:40.83.126.181,服务器:127.0.0.1, 请求:“GET / HTTP/1.1”,上游:“fastcgi://127.0.0.1:9000”,主机: “www.mysite.com”

nginx.conf:

worker_processes  1;

events {
    worker_connections  1024; 
}


http{

    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  127.0.0.1;

        location / {
            root   /www;
            index  index.html index.htm index.php;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
        }

    }


    include vhost/*.conf; 
}

vhosts/home.conf:

server {
    listen       80;
    server_name  www.mysite.com
    #charset utf-8;
    access_log  /www/host.access.log;
    error_log   /www/error.log;
    root /www;
    index       index.php index.html index.htm;
    location / {
        if (!-e $request_filename) {
           rewrite  ^/(.*)$  /index.php/$1  last;
           break;
        }
    }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
        expires 100d;
    }
    location ~ .*\.(js|css)?$ {
        expires 30d;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

    location ~ \.php(/|$) {
        root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
    }

}

【问题讨论】:

  • 请检查您的 php-fpm 是否正在运行,或者您正在使用套接字作为 unix 路径。

标签: nginx fastcgi


【解决方案1】:

运行php-fpm,确认nginx和php-fpm在同一个用户(组)下,问题就解决了。

【讨论】:

    猜你喜欢
    • 2011-05-14
    • 2019-06-05
    • 2015-08-10
    • 2019-06-12
    • 2021-11-19
    • 2012-09-25
    • 2014-12-07
    • 2020-09-29
    • 2012-07-16
    相关资源
    最近更新 更多