【问题标题】:Getting Connection reset by peer) while proxying upgraded connection & Connection refused while connecting to upstream由对等方重置连接)同时代理升级的连接和连接到上游时连接被拒绝
【发布时间】:2018-09-04 09:34:32
【问题描述】:

我的 nginx 日志中出现这些错误已经有一段时间了。 我最近没有看到网站性能有任何问题,但是当我们连接超过 1000 个用户时,我们会遇到问题。

这里有一些错误日志

2018/03/23 20:14:18 [错误] 1356#0: *540195 recv() 失败 (104: 对等方重置连接)同时代理升级的连接,客户端: 10.253.220.93,服务器:playtest2.ea.com,请求:“GET /socket.io/?email=email&name=name&clientId=35e9c1be-f1fc-4e34-ba68-ce72c6e905c8&version=2.0.0.1704&fullName=test&EIO=3&transport=websocket&t=6365730725746 -17 HTTP/1.1",上游: "http://127.0.0.1:3000/socket.io/?email=email&name=DICELA-RSTAR&clientId=35e9c1be-f1fc-4e34-ba68-ce72c6e905c8&version=2.0.0.1704&fullName=Dtest&EIO=3&transport=websocket&t=636573072574620756-17", 主机:“playtest2.xx.com”

2018/03/23 20:14:18 [错误] 1356#0: *867401 connect() 失败 (111: 连接被拒绝)同时连接到上游,客户端: 10.xx.xxx.211,服务器:playtest2.xx.com,请求:“GET /bin/PlaytestMateSetup.exe.json HTTP/1.1”,上游: “http://127.0.0.1:3000/bin/PlaytestMateSetup.exe.json”,主持人: “playtest2.xx.com”

这是我的 nginx 配置文件,任何帮助将不胜感激。

服务器模块列在另一个目录下。

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
worker_rlimit_nofile 30000;
debug_points abort;
worker_rlimit_core 500M;
events {
    worker_connections 8024; ## Default: 1024;
#    use epoll;
#    multi_accept on;
}

http {
    include       /etc/nginx/mime.types;
    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;
    server_names_hash_bucket_size 128;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout  180m;

    error_page 404 /offline_error.html;
        location = /offline_error.html {
                root /opt/ptm/server-src/views;
                internal;
        }

#    open_file_cache max=1000 inactive=1200s;
#    open_file_cache_valid 1800s;
#    open_file_cache_min_uses 5;
#    open_file_cache_errors off;

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

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

}

【问题讨论】:

    标签: nginx


    【解决方案1】:

    到此https://www.nginx.com/blog/websocket-nginx/

       map $http_upgrade $connection_upgrade {
         default     upgrade;
         ''          close;
       }
       
       server xxx {
         ...
         location /socket.io/ {
           proxy_pass http://127.0.0.1:3000;
           proxy_http_version 1.1;
           proxy_set_header Upgrade $http_upgrade;
           proxy_set_header Connection "Upgrade";
           proxy_set_header Host $host;
           proxy_connect_timeout 15s;
           proxy_send_timeout 3600s; # ws will open for 1 hour
           proxy_read_timeout 3600s; # ws will open for 1 hour
           proxy_buffers 512 256M;
           proxy_buffer_size 256M;
         }
       }
    

    【讨论】:

    • 应该是:proxy_set_header Connection $connection_upgrade;而不是 proxy_set_header 连接“升级”;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-03
    • 1970-01-01
    • 2014-02-26
    • 2012-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多