Nginx代理nginx.conf配置——反向代理(对WebSocket支持)

一、需求说明

基于Nginx代理nginx.conf配置——反向代理,如果要添加websocket支持,需要进行如下配置

二、配置内容

在http中添加一下配置,添加对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;	
	    }
    }

}

三、配置结果

配置后重新运行nginx后,websocket即可成功代理。注意防火墙端口是否开放、nginx如果使用docker,其对应的端口是否映射出来。

猜你喜欢

转载自blog.csdn.net/pp_lan/article/details/131593365
今日推荐