求助, nginx 做正向代理出现 502 bad gateway

331 天前
 yeccc

使用 nginx 做内网服务器的正向代理,更新 npm 依赖的时候会出现 502

nginx 配置

worker_processes  auto;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

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

    gzip                       on;
    gzip_http_version          1.0;
    gzip_comp_level            6;
    gzip_proxied               any;
   #gzip_min_length            500;
    gzip_buffers               16 8k;
    gzip_types       text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php application/javascript application/json;


server {
    charset utf-8;
    resolver 114.114.114.114;
    listen       880 default_server;

    proxy_connect;
    proxy_connect_allow all; 
    proxy_connect_connect_timeout 60s;
    proxy_connect_read_timeout 60s;
    proxy_connect_send_timeout 60s;

    access_log      logs/proxy_access.log ty_proxy_log_format;

    location / {
        proxy_pass $scheme://$host$request_uri;     
        proxy_set_header HOST $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_redirect off;
        proxy_set_header X-NginX-Proxy true;
        proxy_ssl_server_name on;

        proxy_connect_timeout 600;
        proxy_read_timeout 600;
        proxy_send_timeout 600;
        proxy_buffer_size 64k;
        proxy_buffers   4 32k;
        proxy_busy_buffers_size 64k;
        proxy_temp_file_write_size 64k;
        proxy_next_upstream error timeout invalid_header http_502;
    }


    error_page 405 =200 @405;
    location @405 {
        proxy_method GET;
        proxy_pass $scheme://$host/$request_uri;
    }

    }

    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

nginx 日志

access 日志
[23/Jun/2023:17:00:29 +0800] "CONNECT registry.npmmirror.com:443 HTTP/1.1" 502 157 "-" "-" "-" "-"

error 日志
2023/06/23 17:00:29 [error] 26952#45320: *3314 proxy_connect: upstream connect failed (10051: A socket operation was attempted to an unreachable network) while connecting to upstream, client: 172.30.30.80, server: , request: "CONNECT registry.npmmirror.com:443 HTTP/1.1", host: "registry.npmmirror.com"

1067 次点击
所在节点    程序员
2 条回复
rekulas
331 天前
感觉是 registry.npmmirror.com 443 连不上 服务器网络问题
yeccc
331 天前
@rekulas 没次会有一两个依赖出现 502 其他都正常

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/951047

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX