nginx wss重定向配置
时间: 2023-11-20 14:52:47 浏览: 104
为了实现nginx wss重定向配置,可以按照以下步骤进行操作:
1. 在nginx配置文件中添加以下代码:
```
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
server_name yourdomain.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name yourdomain.com;
ssl_certificate /path/to/your/cert.pem;
ssl_certificate_key /path/to/your/key.pem;
location / {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
```
2. 修改以上代码中的yourdomain.com为你的域名,/path/to/your/cert.pem和/path/to/your/key.pem为你的SSL证书和私钥的路径,proxy_pass http://localhost:8080为你的WebSocket服务器地址。
3. 启动nginx,执行命令:/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf。
4. 检查nginx配置文件是否正确,执行命令:/usr/local/nginx/sbin/nginx -t。
阅读全文
相关推荐











