Nginx代理Websocket端口配置

Nginx代理Websocket端口配置

1、加入Nginx代理配置

#WS和Http协议转换
map $http_upgrade $connection_upgrade { 
    default          keep-alive;
    'websocket'      upgrade;
}

server {
    #WS端口-需要代理的端口
    listen       1111;
    server_name   localhost;
   
   #路径配置-WS后缀
   location /websocket {
        #目标地址
        proxy_pass http://127.0.0.1:80/websocket;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
    }
}

2、重启Nginx

#Nginx相关命令
systemctl stop nginx
systemctl start nginx
systemctl restart nginx

#查看监听端口
netstat -anp|grep 您的端口

版权声明:本文为weixin_44187730原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。