byebyehair/minichat

IP+端口 可以支持使用,NGINX反代之后域名访问无法正常使用

Closed this issue · 2 comments

VPS docker部署
IP+端口 可以正常访问使用
NGINX反代之后用域名访问,输入信息后发送,提示:The connection is closed,please refresh the page to reconnect !
请问大佬配置文件中 server_url: "" 中要填写什么吗

理论上来说,你不需要填写server_url,除非你的页面和后端没有使用同源。
如果要修改,就填写你反代的域名,比如a.com反代127.0.0.1:8888,那么填写a.com即可。
但你的问题应该不是没有填写server_url导致的。
大概率是因为你的nginx配置文件没有加入以下:
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;

正确的例子:


location ^~ /
{
    proxy_pass http://被反代的IP或域名:被反代的端口;
    proxy_set_header Host 127.0.0.1;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_http_version 1.1;
    add_header X-Cache $upstream_cache_status;
}

搞掂了,开启 websockets 支持即可