nginx 更改上游服务器的端口检查

问题描述

我使用 Nginx 作为我的节点应用程序的反向代理,该应用程序使用 pm2 在集群模式下运行。我的节点应用程序在 4000 端口提供服务。我的 Nginx 配置是

server{

     listen      80;
     listen      [::]:80;
     server_name  domain_name
     root       path to static file;

     return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
      server_name  domain_name
     root       path to static file;

    ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/domain.com/privkey.pem;
    ssl_session_timeout 1d;
    ssl_session_cache shared:MozSSL:10m;  # about 40000 sessions
    ssl_session_tickets off;

    # curl https://ssl-config.mozilla.org/ffdhe2048.txt > /path/to/dhparam
    #ssl_dhparam /path/to/dhparam;

    # intermediate configuration
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-poly1305:ECDHE$

    ssl_prefer_server_ciphers on;

    # HSTS (ngx_http_headers_module is required) (63072000 seconds)
    add_header Strict-Transport-Security "max-age=63072000" always;

    # OCSP stapling
    ssl_stapling on;
    ssl_stapling_verify on;

 # verify chain of trust of OCSP response using Root CA and Intermediate certs
    # replace with the IP address of your resolver
    resolver 8.8.8.8;

     location /api{
        proxy_pass http://localhost:4000/api;
        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;
     }

     location / {
        try_files $uri /index.html;
     }

     error_page  404  /404.html;
        location = /40x.html{
     }

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

}

有些人可以访问该网站,有些人无法访问,当我检查错误日志时,它是这样的:

2021/04/12 08:47:25 [error] 20144#20144: *2599 connect() Failed (111: Connection refused) while connecting to upstream,client: 127.0.0.1,server: localhost,request: "GET / HTTP/1.0",upstream: "http://127.0.0.1:8080/"

我的服务器运行在4000,那么为什么Nginx会尝试连接8080端口?当我将服务器端口更改为 8080 一段时间后,错误日志变为

2021/04/12 08:47:25 [error] 20144#20144: *2599 connect() Failed (111: Connection refused) while connecting to upstream,upstream: "http://127.0.0.1:8443/"

我怎么能说 Nginx 在指定端口检查上游服务器?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)