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

查看 66|回复 2
作者: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"

Nginx, Location, host, Text

rekulas   
感觉是 registry.npmmirror.com 443 连不上 服务器网络问题
yeccc
OP
  
@rekulas 没次会有一两个依赖出现 502 其他都正常
您需要登录后才可以回帖 登录 | 立即注册

返回顶部