Nachdem der Nginx-Proxy-Socket eine Verbindung zum Cluster hergestellt hat, wird die Verbindung häufig getrennt und erneut hergestellt.


1. Szene

Nginx verwendet den Cluster-Modus, um mehrere Socket-Links als Proxy zu verwenden, und die Socket-Links werden häufig getrennt und wieder verbunden.


2. Die spezifische Leistung ist wie folgt

Fügen Sie hier eine Bildbeschreibung ein


3. Nginx-Proxy-Konfiguration

## socket集群
upstream test_socket {
    
    
	server 192.168.1.233:9901;
	server 192.168.1.243:9901;
}

server {
    
    
    listen       8600;
    server_name  localhost;

    location / {
    
    
        root   html;
        index  index.html index.htm;
    }
    
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
    
    
        root   html;
    }
	
	
	## socket.io
	location ~* /socket.io/* {
    
    
		proxy_pass http://test_socket;
		
		# WebScoket Support
		proxy_http_version 1.1;
		# webscoekt超时时间,如果没有做心跳之类的动作需要配置
		proxy_read_timeout 700s;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection "upgrade";
		
		proxy_set_header Origin xxx;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header Host $http_host;
		proxy_set_header X-NginX-Proxy true;
		break;
	}
}

4. Nginx-Fehlermeldung

1. Nginx-Fehlerprotokoll

2023/08/30 11:22:19 [error] 192424#0: *109446 upstream prematurely closed connection while reading upstream, client: 192.168.4.10, server: localhost, request: "POST /socket.io/?EIO=3&transport=polling&t=Of4Tg3l&sid=75b5dd34-7636-4683-8848-402ba4a5d0d4 HTTP/1.1", upstream: "http://192.168.1.243:9901/socket.io/?EIO=3&transport=polling&t=Of4Tg3l&sid=75b5dd34-7636-4683-8848-402ba4a5d0d4", host: "192.168.1.233:8600", referrer: "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1"
2023/08/30 11:22:19 [error] 192424#0: *109450 upstream prematurely closed connection while reading upstream, client: 192.168.4.10, server: localhost, request: "POST /socket.io/?EIO=3&transport=polling&t=Of4Tg3u&sid=75b5dd34-7636-4683-8848-402ba4a5d0d4 HTTP/1.1", upstream: "http://192.168.1.243:9901/socket.io/?EIO=3&transport=polling&t=Of4Tg3u&sid=75b5dd34-7636-4683-8848-402ba4a5d0d4", host: "192.168.1.233:8600", referrer: "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1"
2023/08/30 11:22:20 [error] 192424#0: *109453 upstream prematurely closed connection while reading upstream, client: 192.168.4.10, server: localhost, request: "POST /socket.io/?EIO=3&transport=polling&t=Of4TgF_&sid=fe446904-412b-487b-b0ca-fe3b153218c5 HTTP/1.1", upstream: "http://192.168.1.243:9901/socket.io/?EIO=3&transport=polling&t=Of4TgF_&sid=fe446904-412b-487b-b0ca-fe3b153218c5", host: "192.168.1.233:8600", referrer: "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1"
2023/08/30 11:22:20 [error] 192424#0: *109451 upstream prematurely closed connection while reading upstream, client: 192.168.4.10, server: localhost, request: "POST /socket.io/?EIO=3&transport=polling&t=Of4TgG7&sid=fe446904-412b-487b-b0ca-fe3b153218c5 HTTP/1.1", upstream: "http://192.168.1.243:9901/socket.io/?EIO=3&transport=polling&t=Of4TgG7&sid=fe446904-412b-487b-b0ca-fe3b153218c5", host: "192.168.1.233:8600", referrer: "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1"
2023/08/30 11:22:21 [error] 192424#0: *109492 upstream prematurely closed connection while reading upstream, client: 192.168.4.10, server: localhost, request: "GET /socket.io/?EIO=3&transport=polling&t=Of4TgYr&sid=e52704e9-f99c-45df-89c1-1d2424277a77 HTTP/1.1", upstream: "http://192.168.1.243:9901/socket.io/?EIO=3&transport=polling&t=Of4TgYr&sid=e52704e9-f99c-45df-89c1-1d2424277a77", host: "192.168.1.233:8600", referrer: "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1"
2023/08/30 11:22:22 [error] 192424#0: *109497 upstream prematurely closed connection while reading upstream, client: 192.168.4.10, server: localhost, request: "POST /socket.io/?EIO=3&transport=polling&t=Of4Tgk1&sid=f5bfb349-17bf-4a81-853c-23c52acf2b35 HTTP/1.1", upstream: "http://192.168.1.233:9901/socket.io/?EIO=3&transport=polling&t=Of4Tgk1&sid=f5bfb349-17bf-4a81-853c-23c52acf2b35", host: "192.168.1.233:8600", referrer: "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1"
2023/08/30 11:22:22 [error] 192424#0: *109505 upstream prematurely closed connection while reading upstream, client: 192.168.4.10, server: localhost, request: "POST /socket.io/?EIO=3&transport=polling&t=Of4Tgk5&sid=f5bfb349-17bf-4a81-853c-23c52acf2b35 HTTP/1.1", upstream: "http://192.168.1.233:9901/socket.io/?EIO=3&transport=polling&t=Of4Tgk5&sid=f5bfb349-17bf-4a81-853c-23c52acf2b35", host: "192.168.1.233:8600", referrer: "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1"
2023/08/30 11:22:23 [error] 192424#0: *109517 upstream prematurely closed connection while reading upstream, client: 192.168.4.10, server: localhost, request: "GET /socket.io/?EIO=3&transport=polling&t=Of4Tg_e&sid=b5c9c6a9-f43c-4455-a001-d2dc6f01c39c HTTP/1.1", upstream: "http://192.168.1.233:9901/socket.io/?EIO=3&transport=polling&t=Of4Tg_e&sid=b5c9c6a9-f43c-4455-a001-d2dc6f01c39c", host: "192.168.1.233:8600", referrer: "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1"
2023/08/30 11:22:23 [error] 192424#0: *109507 upstream prematurely closed connection while reading upstream, client: 192.168.4.10, server: localhost, request: "POST /socket.io/?EIO=3&transport=polling&t=Of4Tg_i&sid=b5c9c6a9-f43c-4455-a001-d2dc6f01c39c HTTP/1.1", upstream: "http://192.168.1.233:9901/socket.io/?EIO=3&transport=polling&t=Of4Tg_i&sid=b5c9c6a9-f43c-4455-a001-d2dc6f01c39c", host: "192.168.1.233:8600", referrer: "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1"
2023/08/30 11:22:24 [error] 192424#0: *109526 upstream prematurely closed connection while reading upstream, client: 192.168.4.10, server: localhost, request: "GET /socket.io/?EIO=3&transport=polling&t=Of4ThLE&sid=a7896c79-b510-4a37-bf65-8eded388bef3 HTTP/1.1", upstream: "http://192.168.1.233:9901/socket.io/?EIO=3&transport=polling&t=Of4ThLE&sid=a7896c79-b510-4a37-bf65-8eded388bef3", host: "192.168.1.233:8600", referrer: "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1"
2023/08/30 11:22:24 [error] 192424#0: *109531 upstream prematurely closed connection while reading upstream, client: 192.168.4.10, server: localhost, request: "POST /socket.io/?EIO=3&transport=polling&t=Of4ThLJ&sid=a7896c79-b510-4a37-bf65-8eded388bef3 HTTP/1.1", upstream: "http://192.168.1.233:9901/socket.io/?EIO=3&transport=polling&t=Of4ThLJ&sid=a7896c79-b510-4a37-bf65-8eded388bef3", host: "192.168.1.233:8600", referrer: "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1"
2023/08/30 11:22:26 [error] 192424#0: *109533 upstream prematurely closed connection while reading upstream, client: 192.168.4.10, server: localhost, request: "POST /socket.io/?EIO=3&transport=polling&t=Of4Thcj&sid=ee4e2bf1-fc65-4652-99f5-d60e91e88ac3 HTTP/1.1", upstream: "http://192.168.1.233:9901/socket.io/?EIO=3&transport=polling&t=Of4Thcj&sid=ee4e2bf1-fc65-4652-99f5-d60e91e88ac3", host: "192.168.1.233:8600", referrer: "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1"
2023/08/30 11:22:26 [error] 192424#0: *109541 upstream prematurely closed connection while reading upstream, client: 192.168.4.10, server: localhost, request: "POST /socket.io/?EIO=3&transport=polling&t=Of4Thco&sid=ee4e2bf1-fc65-4652-99f5-d60e91e88ac3 HTTP/1.1", upstream: "http://192.168.1.233:9901/socket.io/?EIO=3&transport=polling&t=Of4Thco&sid=ee4e2bf1-fc65-4652-99f5-d60e91e88ac3", host: "192.168.1.233:8600", referrer: "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1"
2023/08/30 11:22:26 [error] 192424#0: *109543 upstream prematurely closed connection while reading upstream, client: 192.168.4.10, server: localhost, request: "POST /socket.io/?EIO=3&transport=polling&t=Of4Thkr&sid=06815ca2-fd5d-4d83-87f3-344dac41a60a HTTP/1.1", upstream: "http://192.168.1.233:9901/socket.io/?EIO=3&transport=polling&t=Of4Thkr&sid=06815ca2-fd5d-4d83-87f3-344dac41a60a", host: "192.168.1.233:8600", referrer: "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1"

2. Nginx-Zugriffsprotokoll

192.168.4.10 - - [30/Aug/2023:14:10:29 +0800] "GET /socket.io/?EIO=3&transport=websocket&sid=44896d85-8569-42c3-adc6-7ce49132f6f0 HTTP/1.1" 101 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:29 +0800] "GET /socket.io/?EIO=3&transport=polling&t=Of549Rf&sid=44896d85-8569-42c3-adc6-7ce49132f6f0 HTTP/1.1" 200 42 "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:29 +0800] "POST /socket.io/?EIO=3&transport=polling&t=Of549Rk&sid=44896d85-8569-42c3-adc6-7ce49132f6f0 HTTP/1.1" 500 0 "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:29 +0800] "POST /socket.io/?EIO=3&transport=polling&t=Of549Rp&sid=44896d85-8569-42c3-adc6-7ce49132f6f0 HTTP/1.1" 200 39 "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:29 +0800] "GET /socket.io/?EIO=3&transport=polling&t=Of549Rk.0&sid=44896d85-8569-42c3-adc6-7ce49132f6f0 HTTP/1.1" 500 0 "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:30 +0800] "GET /socket.io/?EIO=3&transport=polling&t=Of549ic HTTP/1.1" 200 147 "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:30 +0800] "GET /socket.io/?EIO=3&transport=websocket&sid=1c735e86-00ba-4125-9cbf-c3923feda84e HTTP/1.1" 101 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:30 +0800] "GET /socket.io/?EIO=3&transport=polling&t=Of549ik&sid=1c735e86-00ba-4125-9cbf-c3923feda84e HTTP/1.1" 200 42 "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:30 +0800] "POST /socket.io/?EIO=3&transport=polling&t=Of549ip&sid=1c735e86-00ba-4125-9cbf-c3923feda84e HTTP/1.1" 500 0 "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:30 +0800] "POST /socket.io/?EIO=3&transport=polling&t=Of549iu&sid=1c735e86-00ba-4125-9cbf-c3923feda84e HTTP/1.1" 500 0 "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:31 +0800] "GET /socket.io/?EIO=3&transport=polling&t=Of549vb HTTP/1.1" 200 147 "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:31 +0800] "GET /socket.io/?EIO=3&transport=websocket&sid=cb931664-f714-4e01-8c60-d1dd515473a3 HTTP/1.1" 101 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:31 +0800] "GET /socket.io/?EIO=3&transport=polling&t=Of549vj&sid=cb931664-f714-4e01-8c60-d1dd515473a3 HTTP/1.1" 200 42 "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:31 +0800] "POST /socket.io/?EIO=3&transport=polling&t=Of549vo&sid=cb931664-f714-4e01-8c60-d1dd515473a3 HTTP/1.1" 500 0 "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:31 +0800] "POST /socket.io/?EIO=3&transport=polling&t=Of549vw&sid=cb931664-f714-4e01-8c60-d1dd515473a3 HTTP/1.1" 500 0 "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:32 +0800] "GET /socket.io/?EIO=3&transport=polling&t=Of54A3O HTTP/1.1" 200 146 "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:32 +0800] "GET /socket.io/?EIO=3&transport=websocket&sid=e9808cde-0f07-4539-9b60-20bf099e12f4 HTTP/1.1" 101 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:32 +0800] "GET /socket.io/?EIO=3&transport=polling&t=Of54A3V&sid=e9808cde-0f07-4539-9b60-20bf099e12f4 HTTP/1.1" 200 42 "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:32 +0800] "POST /socket.io/?EIO=3&transport=polling&t=Of54A3a&sid=e9808cde-0f07-4539-9b60-20bf099e12f4 HTTP/1.1" 500 0 "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"


5. Server-Socket-Link-Protokoll

2023-08-30 14:28:59.128 - [ERROR] - [nioEventLoopGroup-3-16] - [c.c.socketio.transport.PollingTransport - line:147]: c40dc987-8544-47b5-958b-3952967f1d47 is not registered. Closing connection
2023-08-30 14:28:59.147 - [ERROR] - [nioEventLoopGroup-3-17] - [c.c.socketio.transport.PollingTransport - line:168]: dc0fa35e-35a3-45fd-9a9e-26ba4746b4c8 is not registered. Closing connection
2023-08-30 14:28:59.588 - [INFO ] - [nioEventLoopGroup-3-18] - [com.xxx.socket.hander.SocketService - line:60]: 192.168.1.233:52116 移动客户端接入!
2023-08-30 14:28:59.588 - [INFO ] - [nioEventLoopGroup-3-18] - [com.xxx.socket.interceptor.EventListener - line:40]: 建立连接
2023-08-30 14:28:59.599 - [INFO ] - [nioEventLoopGroup-3-19] - [com.xxx.socket.hander.SocketService - line:68]: 192.168.1.233:52116 移动客户端已断开连接!
2023-08-30 14:28:59.599 - [INFO ] - [nioEventLoopGroup-3-19] - [com.xxx.socket.interceptor.EventListener - line:60]: 关闭连接。。。。。。。。。
2023-08-30 14:28:59.760 - [INFO ] - [nioEventLoopGroup-3-20] - [com.xxx.socket.hander.SocketService - line:60]: 192.168.1.233:52124 移动客户端接入!
2023-08-30 14:28:59.760 - [INFO ] - [nioEventLoopGroup-3-20] - [com.xxx.socket.interceptor.EventListener - line:40]: 建立连接
2023-08-30 14:28:59.767 - [INFO ] - [nioEventLoopGroup-3-21] - [com.xxx.socket.hander.SocketService - line:68]: 192.168.1.233:52124 移动客户端已断开连接!
2023-08-30 14:28:59.767 - [INFO ] - [nioEventLoopGroup-3-21] - [com.xxx.socket.interceptor.EventListener - line:60]: 关闭连接。。。。。。。。。
2023-08-30 14:29:00.257 - [INFO ] - [nioEventLoopGroup-3-22] - [com.xxx.socket.hander.SocketService - line:60]: 192.168.1.233:52132 移动客户端接入!
2023-08-30 14:29:00.258 - [INFO ] - [nioEventLoopGroup-3-22] - [com.xxx.socket.interceptor.EventListener - line:40]: 建立连接
2023-08-30 14:29:00.263 - [INFO ] - [nioEventLoopGroup-3-23] - [com.xxx.socket.hander.SocketService - line:68]: 192.168.1.233:52132 移动客户端已断开连接!
2023-08-30 14:29:00.263 - [INFO ] - [nioEventLoopGroup-3-23] - [com.xxx.socket.interceptor.EventListener - line:60]: 关闭连接。。。。。。。。。
2023-08-30 14:29:00.534 - [ERROR] - [nioEventLoopGroup-3-24] - [c.c.socketio.transport.PollingTransport - line:168]: 1a348191-8b2a-42fc-b08e-552e5029507b is not registered. Closing connection
2023-08-30 14:29:00.538 - [ERROR] - [nioEventLoopGroup-3-25] - [c.c.socketio.transport.PollingTransport - line:147]: 1a348191-8b2a-42fc-b08e-552e5029507b is not registered. Closing connection
2023-08-30 14:29:00.742 - [ERROR] - [nioEventLoopGroup-3-26] - [c.c.socketio.transport.PollingTransport - line:168]: 7740ce73-8509-4233-a735-3c436a144d0e is not registered. Closing connection
2023-08-30 14:29:00.747 - [ERROR] - [nioEventLoopGroup-3-27] - [c.c.socketio.transport.PollingTransport - line:147]: 7740ce73-8509-4233-a735-3c436a144d0e is not registered. Closing connection
2023-08-30 14:29:02.047 - [INFO ] - [nioEventLoopGroup-3-28] - [com.xxx.socket.hander.SocketService - line:60]: 192.168.1.233:52156 移动客户端接入!
2023-08-30 14:29:02.047 - [INFO ] - [nioEventLoopGroup-3-28] - [com.xxx.socket.interceptor.EventListener - line:40]: 建立连接
2023-08-30 14:29:02.049 - [INFO ] - [nioEventLoopGroup-3-29] - [com.xxx.socket.hander.SocketService - line:60]: 192.168.1.233:52160 移动客户端接入!
2023-08-30 14:29:02.049 - [INFO ] - [nioEventLoopGroup-3-29] - [com.xxx.socket.interceptor.EventListener - line:40]: 建立连接

Aus dem Protokoll ist ersichtlich, dass die Häufigkeit der Trennung und Wiederverbindung sehr hoch ist und alle zehn Millisekunden eine Verbindung hergestellt wird.


6. Gründe

Es liegt ein Problem mit der Lastausgleichsstrategie des Nginx-Clusters vor. Da keine test_socket集群Strategie angegeben ist, verwendet Nginx standardmäßig diese轮询策略

Warum führt die Polling-Strategie dazu, dass der Socket ständig neu verbunden wird?

Dies liegt daran, dass der WebSocket-Protokoll-Handshake-Prozess nicht in einem Schritt erfolgt. Er ist in mehrere Schritte unterteilt. Wenn beim letzten Mal Server 1 die Hand geschüttelt wurde und beim nächsten Mal Server 2 die Hand geschüttelt wurde, dann der Handshake-Prozess wird definitiv nicht normal abgeschlossen, und die Verbindung wird nicht hergestellt. Sie kann nicht normal hergestellt werden.


7. Lösen

Da der Grund darin liegt, dass die Socket-Verbindung nicht mit dem festen Server kommunizieren kann, lösen Sie einfach dieses Problem.

1. Geben Sie die Lastausgleichsstrategie für den Socket-Cluster an:ip_hash

## socket集群
upstream test_socket {
    
    
	# ip_hash:根据IP地址决定具体访问的服务器
	ip_hash;
	server 192.168.1.233:9901;
	server 192.168.1.243:9901;
}

2. Starten Sie Nginx neu

Guess you like

Origin blog.csdn.net/weixin_52116015/article/details/132835477