首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >nginx配置websocket支持wss

nginx配置websocket支持wss

作者头像
后端技术探索
发布2018-12-24 14:37:44
7.6K0
发布2018-12-24 14:37:44
举报
文章被收录于专栏:后端技术探索后端技术探索

如下配置nginx

map $http_upgrade $connection_upgrade {  
    default upgrade;  
    '' close;  
}  
upstream websocket {  
    server 128.190.82.105:8888;  
}  
server {  
    listen 8888;  
    server_name proxy.hello.com;
    ssl on;
    ssl_certificate /etc/nginx/ssl/hello.com_bundle.crt;
    ssl_certificate_key /etc/nginx/ssl/hello.com.key;
    ssl_session_timeout 20m;
    ssl_verify_client off;
    location / {  
        proxy_pass http://websocket;  
        proxy_http_version 1.1;  
        proxy_set_header Upgrade $http_upgrade;  
        proxy_set_header Connection "Upgrade";  
    }  
}

128.190.82.105:8888是真正的服务端地址,nginx所在域名是proxy.hello.com,代理的端口号是8888,所以前端访问的时候这样配置:

WEBSOCKET_URL: 'wss://proxy.hello.com:8888',  

image.png

检查nginx.conf正确性:

nginx -t

重新加载配置文件:

nginx -s reload
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2018-12-04,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 nginx 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档