简体   繁体   English

Nginx 有时“连接()失败(111:连接被拒绝)同时连接到上游”

[英]Nginx sometime “connect() failed (111: Connection refused) while connecting to upstream”

I have nginx with node js its work fine.我有 nginx 和 node js 工作正常。 but the problem sometime i can't access some route.但有时我无法访问某些路线的问题。 and show error connect() failed (111: Connection refused) and work again.并显示错误 connect() failed (111: Connection refused) 并再次工作。 idk why thats happed.我知道为什么会这样。 this the error.log这是error.log

2019/11/18 04:04:17 [error] 9234#0: *38237 connect() failed (111: Connection refused) while connecting to upstream, client: 180.246.173.22, server: loganganteng.site, request: "GET /timeline/loadEditorChoice HTTP/2.0", upstream: "http://172.20.0.2:3000/timeline/loadEditorChoice", host: "loganganteng.site"
2019/11/18 04:04:17 [error] 9234#0: *38237 connect() failed (111: Connection refused) while connecting to upstream, client: 180.246.173.22, server: loganganteng.site, request: "GET /timeline/loadLatestPopular HTTP/2.0", upstream: "http://172.20.0.2:3000/timeline/loadLatestPopular", host: "loganganteng.site"
2019/11/18 04:04:17 [error] 9234#0: *38237 connect() failed (111: Connection refused) while connecting to upstream, client: 180.246.173.22, server: loganganteng.site, request: "GET /timeline/loadLatestPost HTTP/2.0", upstream: "http://172.20.0.2:3000/timeline/loadLatestPost", host: "loganganteng.site"

and this the access.log这是access.log

180.246.173.22 - - [18/Nov/2019:04:04:17 +0000] "GET /timeline/loadEditorChoice HTTP/2.0" 502 3693 "-" "okhttp/3.12.0" "-"
180.246.173.22 - - [18/Nov/2019:04:04:17 +0000] "GET /timeline/loadLatestPopular HTTP/2.0" 502 3693 "-" "okhttp/3.12.0" "-"
180.246.173.22 - - [18/Nov/2019:04:04:17 +0000] "GET /timeline/loadLatestPost HTTP/2.0" 502 3693 "-" "okhttp/3.12.0" "-"

the error is not always.错误并非总是如此。 but sometime.但有时。 i put the nginx config too我也把 nginx 配置

     upstream socket_nodes {
    ip_hash;
    server 172.20.0.2:3000;
 }

 server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    #listen 80;
    #listen [::]:80;
    server_name  loganganteng.site;
    #root         /usr/share/nginx/html;

    ssl_certificate /etc/letsencrypt/live/loganganteng.site/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/loganganteng.site/privkey.pem;
    ssl_session_timeout 1d;
    ssl_session_cache shared:SSL:50m;
    ssl_session_tickets off;

    # modern configuration. tweak to your needs.
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:ECDHE-RSA-DES-CBC3-SHA:ECDHE-ECDSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:DES-CBC3-SHA:HIGH:SEED:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!RSAPSK:!aDH:!aECDH:!EDH-DSS-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA:!SRP';
    ssl_prefer_server_ciphers on;

    add_header Strict-Transport-Security max-age=15768000;

    ssl_stapling on;
    ssl_stapling_verify on;

    resolver 8.8.8.8;
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    location /socket.io/ {
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_pass http://socket_nodes;
    }

    location / {
        proxy_pass "http://172.20.0.2:3000/";
    }

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

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

}

this default config这个默认配置

    user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
worker_rlimit_nofile 20000;

include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 20000;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        include /etc/nginx/default.d/*.conf;

        location / {
        }

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

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

It maybe port problem.可能是端口问题。 use this command sudo lsof -i -P -n | grep LISTEN使用此命令sudo lsof -i -P -n | grep LISTEN sudo lsof -i -P -n | grep LISTEN and check if required port is running. sudo lsof -i -P -n | grep LISTEN并检查所需端口是否正在运行。 If not, check your logs for error (ex: pm2 log ).如果没有,请检查您的日志是否有错误(例如: pm2 log )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 连接到上游时,nginx&nodejs:connect()失败(111:连接被拒绝) - nginx & nodejs: connect() failed (111: Connection refused) while connecting to upstream 连接到上游时,NodeJS connect()失败(111:连接被拒绝) - NodeJS connect() failed (111: Connection refused) while connecting to upstream Nginx 错误失败(111:连接被拒绝)同时连接到上游,docker-compose nodejs - Nginx error failed (111: Connection refused) while connecting to upstream, docker-compose nodejs AWS弹性Beanstalk / nginx:connect()失败(111:连接被拒绝 - AWS elastic Beanstalk / nginx : connect() failed (111: Connection refused 连接被拒绝,同时在 engintron/nginx 部署上连接到上游 - Connection refused, while connecting to upstream on engintron/nginx deployment 在Docker容器内连接到Node.js上游时,Nginx连接被拒绝 - Nginx connection refused while connecting to Node.js upstream inside a Docker container 生产流星应用程序:NginX代理-失败(111:连接被拒绝) - Production meteor app: NginX proxy - failed(111: connection refused) 无法连接到 127.0.0.1:27017,原因:errno:111 连接被拒绝 - Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused MongoDB-无法连接到127.0.0.1:27017,原因:errno:111连接被拒绝 - MongoDB - Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused nginx + node.js =通过iframely连接到上游时失败 - nginx + node.js = failed while connecting to upstream with iframely
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM