小编Mic*_*ann的帖子

wss:// 的 nginx 设置不断收到 301 重定向

无法让 wss:// (或 ws://) 在我的 Digital Ocean、使用 nginx 的 Ubuntu 服务器上工作,不断收到 301 重定向并且没有连接。

Websocket服务器:node + express + uws在http://localhost:3000/chat上提供服务(我已经通过在ufw中打开3000并直接与ws://连接进行了测试,工作正常。)

操作系统:Ubuntu 16.04.3 x64

这是我的 nginx 配置(我尝试了很多变体和选项,这是最简单的,老实说这似乎并不重要)

server {
    listen 443 ssl; # client_wss_port
    server_name www.example.org;

    ssl on;
    ssl_certificate /etc/letsencrypt/live/example.org/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.org/privkey.pem;


    location /chat/ {
        add_header locationischat 1; # this is a dummy header for debugging
        proxy_pass http://localhost:3000/chat/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的 nginx 版本

nginx -v
nginx version: nginx/1.10.3 (Ubuntu)
Run Code Online (Sandbox Code Playgroud)

这是我的防火墙状态

ufw status
Status: …
Run Code Online (Sandbox Code Playgroud)

nginx wss websocket

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

nginx ×1

websocket ×1

wss ×1