原创

配置 nginx 支持 websocket

修改 nginx.conf 文件

http {

    map $http_upgrade $connection_upgrade {
        default upgrade;
        ''   close;
    }

    server {

        location /test/ {
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
        }

    }

}

注意

如果 60 秒内,没有交互消息,连接会断开
因此:websocket 连接后,写个定时任务,每50秒,向后台发送一条消息,防止连接断开

正文到此结束