nginx 上的 502 错误网关

nginx 上的 502 错误网关

我在 nginx 上收到 502 bad gateway,并出现以下错误:

[error] 1679#1679: *13 connect() failed (111: Connection refused) while connecting to upstream, client: 46.176.252.229, server: dodeka-designers.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:3000/", host: "dodeka-designers.com"

这是我的/etc/nginx/sites-available/default内容。有谁知道问题可能是什么?

server {
    listen 80;
        server_name dodeka-designers.com www.dodeka-designers.com;
    location ~ /.well-known {
                allow all;
        }

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        client_max_body_size 50M;
    }

    location /back {
        if ($request_method = 'OPTIONS') {
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
            add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
            add_header 'Access-Control-Max-Age' 1728000;
            add_header 'Content-Type' 'text/plain charset=UTF-8';
            add_header 'Content-Length' 0;
            return 200;
        }
        if ($request_method = 'POST') {
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
            add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
            add_header 'Access-Control-Expose-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
        }
        if ($request_method = 'GET') {
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
            add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
            add_header 'Access-Control-Expose-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
        }
        rewrite ^/back(.*)$ $1 break;
        root /var/www/html;

        client_max_body_size 50M;
            proxy_http_version 1.1;
        proxy_connect_timeout       3600;
        proxy_send_timeout          3600;
        proxy_read_timeout          3600;
        send_timeout                3600;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;

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

    location ~ \.php$ {

        rewrite ^/back(.*)$ $1 break;
        root /var/www/html;

        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;

        client_max_body_size 50M;
            proxy_http_version 1.1;
        proxy_connect_timeout       3600;
        proxy_send_timeout          3600;
        proxy_read_timeout          3600;
        send_timeout                3600;
        fastcgi_read_timeout        3600;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }



    listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/dodeka-designers.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/dodeka-designers.com/privkey.pem; # managed by Certbot
  include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
  ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
 }

答案1

您正在运行一个反向代理,该反向代理试图连接到“http://localhost:3000”上的另一个服务,因此此错误不在 nginx 上,因为 localhost:3000 上的另一个服务没有响应 nginx 请求,或者没有响应它可以正确地由反向代理处理(例如,它正在生成重定向)。

如果你是能够连接到端口3000例如,通过 telnet(执行此测试的命令:)telnet localhost 3000,检查它是否以纯文本形式说话或是否已加密(https...) - 因为您将 nginx 配置为连接到此其他服务http只是,如果您无法连接到端口 3000,那么您必须确定该端口中有哪些服务需要修复,nginx 与此无关。

你没想到 nginx 是一个'反向代理'?然后您需要编辑其配置以删除“代理”行。

相关内容