nginx配置websocket支持wss

参考https://blog.csdn.net/chopin407/article/details/52937645
如下配置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



作者:lunabird
链接:https://www.jianshu.com/p/def7027b787f
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

猜你喜欢

转载自blog.csdn.net/qq_19004627/article/details/88737455
今日推荐