Nginx proxy nginx.conf configuration - reverse proxy (support for WebSocket)

1. Description of requirements

Based on Nginx proxy nginx.conf configuration - reverse proxy , if you want to add websocket support, you need to configure the following

2. Configuration content

Add some configuration in http and add support for websocket


http {
    
    # 配置其它内容

    map $http_upgrade $connection_upgrade {
	default upgrade;
	'' close;
    }
    
    # 配置其它server
	
    server {
	    listen 9016;
	    server_name localhost;

	    location /ws {
		    proxy_pass http://xxx.xxx.xxx.xxx:9016/ws;
		    proxy_http_version 1.1;
	        proxy_set_header Upgrade $http_upgrade;
       		proxy_set_header Connection $connection_upgrade;	
	    }
    }

}

3. Configuration results

After re-running nginx after configuration, websocket can be successfully proxied. Pay attention to whether the firewall port is open, and if nginx uses docker, whether the corresponding port is mapped.

Guess you like

Origin blog.csdn.net/pp_lan/article/details/131593365