V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
yeccc
V2EX  ›  程序员

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

  •  
  •   yeccc · 2023-06-23 17:03:38 +08:00 · 1275 次点击
    这是一个创建于 529 天前的主题,其中的信息可能已经有所发展或是发生改变。

    使用 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"
    
    
    rekulas
        1
    rekulas  
       2023-06-23 17:33:51 +08:00
    感觉是 registry.npmmirror.com 443 连不上 服务器网络问题
    yeccc
        2
    yeccc  
    OP
       2023-06-23 17:39:55 +08:00
    @rekulas 没次会有一两个依赖出现 502 其他都正常
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1574 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 17:02 · PVG 01:02 · LAX 09:02 · JFK 12:02
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.