我使用Socket.io构建和聊天应用程序, 但是在部署到生产服务器之后,Nginx的日志中出现了很多错误:
2016/08/07 09:15:05 [error] 14069#14069: *7875548 upstream prematurely closed connection while reading response header from upstream, client: 171.4.246.202, server: chat.geek4it.com, request: "GET /socket.io/?EIO=3&sid=EIuZoogwZQLJRqqVAMDl&transport=websocket HTTP/1.1", upstream: "http://172.30.31.1:10001/socket.io/?EIO=3&sid=EIuZoogwZQLJRqqVAMDl&transport=websocket", host: "chat.geek4it.com"
2016/08/07 09:15:05 [error] 14069#14069: *7875548 upstream prematurely closed connection while reading response header from upstream, client: 171.4.246.202, server: chat.geek4it.com, request: "GET /socket.io/?EIO=3&sid=EIuZoogwZQLJRqqVAMDl&transport=websocket HTTP/1.1", upstream: "http://172.30.31.1:10007/socket.io/?EIO=3&sid=EIuZoogwZQLJRqqVAMDl&transport=websocket", host: "chat.geek4it.com"
2016/08/07 09:15:25 [error] 14070#14070: *7877071 upstream prematurely closed connection while reading response header from upstream, client: 223.24.40.131, server: chat.geek4it.com, request: "GET /socket.io/?transport=websocket&sid=Vc0WK_sK5E2OW_BKAJXF HTTP/1.1", upstream: "http://172.30.31.1:10007/socket.io/?transport=websocket&sid=Vc0WK_sK5E2OW_BKAJXF", host: "chat.geek4it.com:80"
2016/08/07 09:15:25 [error] 14070#14070: *7877071 upstream prematurely closed connection while reading response header from upstream, client: 223.24.40.131, server: chat.geek4it.com, request: "GET /socket.io/?transport=websocket&sid=Vc0WK_sK5E2OW_BKAJXF HTTP/1.1", upstream: "http://172.30.31.1:10003/socket.io/?transport=websocket&sid=Vc0WK_sK5E2OW_BKAJXF", host: "chat.geek4it.com:80"
2016/08/07 09:15:25 [error] 14070#14070: *7877071 upstream prematurely closed connection while reading response header from upstream, client: 223.24.40.131, server: chat.geek4it.com, request: "GET /socket.io/?transport=websocket&sid=Vc0WK_sK5E2OW_BKAJXF HTTP/1.1", upstream: "http://172.30.31.1:10002/socket.io/?transport=websocket&sid=Vc0WK_sK5E2OW_BKAJXF", host: "chat.geek4it.com:80"
2016/08/07 09:15:25 [error] 14070#14070: *7877071 upstream prematurely closed connection while reading response header from upstream, client: 223.24.40.131, server: chat.geek4it.com, request: "GET /socket.io/?transport=websocket&sid=Vc0WK_sK5E2OW_BKAJXF HTTP/1.1", upstream: "http://172.30.31.1:10001/socket.io/?transport=websocket&sid=Vc0WK_sK5E2OW_BKAJXF", host: "chat.geek4it.com:80"
2016/08/07 09:15:25 [error] 14070#14070: *7877071 upstream prematurely closed connection while reading response header from upstream, client: 223.24.40.131, server: chat.geek4it.com, request: "GET /socket.io/?transport=websocket&sid=Vc0WK_sK5E2OW_BKAJXF HTTP/1.1", upstream: "http://172.30.31.1:10006/socket.io/?transport=websocket&sid=Vc0WK_sK5E2OW_BKAJXF", host: "chat.geek4it.com:80"
2016/08/07 09:15:25 [error] 14070#14070: *7877071 upstream prematurely closed connection while reading response header from upstream, client: 223.24.40.131, server: chat.geek4it.com, request: "GET /socket.io/?transport=websocket&sid=Vc0WK_sK5E2OW_BKAJXF HTTP/1.1", upstream: "http://172.30.31.1:10008/socket.io/?transport=websocket&sid=Vc0WK_sK5E2OW_BKAJXF", host: "chat.geek4it.com:80"
2016/08/07 09:15:25 [error] 14070#14070: *7877071 upstream prematurely closed connection while reading response header from upstream, client: 223.24.40.131, server: chat.geek4it.com, request: "GET /socket.io/?transport=websocket&sid=Vc0WK_sK5E2OW_BKAJXF HTTP/1.1", upstream: "http://172.30.31.1:10005/socket.io/?transport=websocket&sid=Vc0WK_sK5E2OW_BKAJXF", host: "chat.geek4it.com:80"
2016/08/07 09:15:25 [error] 14070#14070: *7877071 upstream prematurely closed connection while reading response header from upstream, client: 223.24.40.131, server: chat.geek4it.com, request: "GET /socket.io/?transport=websocket&sid=Vc0WK_sK5E2OW_BKAJXF HTTP/1.1", upstream: "http://172.30.31.1:10004/socket.io/?transport=websocket&sid=Vc0WK_sK5E2OW_BKAJXF", host: "chat.geek4it.com:80"
2016/08/07 09:15:29 [error] 14069#14069: *7877292 upstream prematurely closed connection while reading response header from upstream, client: 125.25.177.189, server: chat.geek4it.com, request: "GET /socket.io/?EIO=3&sid=QPdEtaKYseDpI2HkAJrB&transport=websocket HTTP/1.1", upstream: "http://172.30.31.1:10008/socket.io/?EIO=3&sid=QPdEtaKYseDpI2HkAJrB&transport=websocket", host: "chat.geek4it.com"
2016/08/07 09:15:29 [error] 14069#14069: *7877292 upstream prematurely closed connection while reading response header from upstream, client: 125.25.177.189, server: chat.geek4it.com, request: "GET /socket.io/?EIO=3&sid=QPdEtaKYseDpI2HkAJrB&transport=websocket HTTP/1.1", upstream: "http://172.30.31.1:10002/socket.io/?EIO=3&sid=QPdEtaKYseDpI2HkAJrB&transport=websocket", host: "chat.geek4it.com"
2016/08/07 09:15:29 [error] 14069#14069: *7877292 upstream prematurely closed connection while reading response header from upstream, client: 125.25.177.189, server: chat.geek4it.com, request: "GET /socket.io/?EIO=3&sid=QPdEtaKYseDpI2HkAJrB&transport=websocket HTTP/1.1", upstream: "http://172.30.31.1:10003/socket.io/?EIO=3&sid=QPdEtaKYseDpI2HkAJrB&transport=websocket", host: "chat.geek4it.com"
2016/08/07 09:15:29 [error] 14069#14069: *7877292 upstream prematurely closed connection while reading response header from upstream, client: 125.25.177.189, server: chat.geek4it.com, request: "GET /socket.io/?EIO=3&sid=QPdEtaKYseDpI2HkAJrB&transport=websocket HTTP/1.1", upstream: "http://172.30.31.1:10006/socket.io/?EIO=3&sid=QPdEtaKYseDpI2HkAJrB&transport=websocket", host: "chat.geek4it.com"
服务器:Socket.io
Android:socket.io-client-java
服务器:AWS EC2
Nginx:nginx / 1.11.3
服务器1:Nginx
Server 2:使用Node.js编写的socket.io实例(使用docker容器运行)
服务器1:
Nginx配置:
upstream chatroom_nodes {
ip_hash;
server 172.30.31.1:10001 weight=10 max_fails=3 fail_timeout=30s;
server 172.30.31.1:10002 weight=10 max_fails=3 fail_timeout=30s;
server 172.30.31.1:10003 weight=10 max_fails=3 fail_timeout=30s;
server 172.30.31.1:10004 weight=10 max_fails=3 fail_timeout=30s;
server 172.30.31.1:10005 weight=10 max_fails=3 fail_timeout=30s;
server 172.30.31.1:10006 weight=10 max_fails=3 fail_timeout=30s;
server 172.30.31.1:10007 weight=10 max_fails=3 fail_timeout=30s;
server 172.30.31.1:10008 weight=10 max_fails=3 fail_timeout=30s;
}
server {
listen 80;
server_name test.geek4it.com;
access_log /var/log/nginx/geek4it/access.log main;
error_log /var/log/nginx/geek4it/error.log warn;
location / {
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://chatroom_nodes;
proxy_redirect off;
proxy_buffers 8 24k;
proxy_buffer_size 2k;
}
}
服务器2:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5e4651be48b5 registry.geek4it.com:5000/chat-runtime:130 "/bin/bash /opt/chatr" 26 hours ago Up 25 hours 0.0.0.0:10004->3000/tcp chatroom-4_1
6fedbde6383e registry.geek4it.com:5000/chat-runtime:130 "/bin/bash /opt/chatr" 26 hours ago Up 25 hours 0.0.0.0:10005->3000/tcp chatroom-5_1
129e8ae422be registry.geek4it.com:5000/chat-runtime:130 "/bin/bash /opt/chatr" 26 hours ago Up 25 hours 0.0.0.0:10002->3000/tcp chatroom-2_1
857d03c18649 registry.geek4it.com:5000/chat-runtime:130 "/bin/bash /opt/chatr" 26 hours ago Up 25 hours 0.0.0.0:10008->3000/tcp chatroom-8_1
625dc44e81ef registry.geek4it.com:5000/chat-runtime:130 "/bin/bash /opt/chatr" 26 hours ago Up 25 hours 0.0.0.0:10000->3000/tcp chatroom-0_1
b99334904496 registry.geek4it.com:5000/chat-runtime:130 "/bin/bash /opt/chatr" 26 hours ago Up 25 hours 0.0.0.0:10006->3000/tcp chatroom-6_1
ea648a3913d6 registry.geek4it.com:5000/chat-runtime:130 "/bin/bash /opt/chatr" 26 hours ago Up 25 hours 0.0.0.0:10007->3000/tcp chatroom-7_1
4a8884303dbc registry.geek4it.com:5000/chat-runtime:130 "/bin/bash /opt/chatr" 26 hours ago Up 24 hours 0.0.0.0:10001->3000/tcp chatroom-1_1
d83e11a1fca5 registry.geek4it.com:5000/chat-runtime:130 "/bin/bash /opt/chatr" 26 hours ago Up 24 hours 0.0.0.0:10003->3000/tcp chatroom-3_1
PS:我使用http协议如:http://xxxxx连接到服务器。