Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade failed: websocket: request origin not allowed by Upgrader.CheckOrigin 跨域访问不了呢,家宽 #2

Open
bcoderi opened this issue Jul 30, 2023 · 5 comments

Comments

@bcoderi
Copy link

bcoderi commented Jul 30, 2023

Upgrade failed: websocket: request origin not allowed by Upgrader.CheckOrigin

跨域访问不了呢,家宽

@srcrs
Copy link
Owner

srcrs commented Jul 30, 2023

是使用了反代吗,提供一下配置信息

@bcoderi
Copy link
Author

bcoderi commented Jul 30, 2023

是使用了反代吗,提供一下配置信息

用的是NginxProxyManager的docker做的反代,没有额外写Nginx代码。
NginxProxyManager:https://nginxproxymanager.com

@srcrs
Copy link
Owner

srcrs commented Jul 31, 2023

location /ws {
        proxy_pass http://localhost:8080/ws;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Host $host;
}

/ws接口使用了websocket,参考下这里怎么配置

@bcoderi
Copy link
Author

bcoderi commented Jul 31, 2023

location /ws

g了好多种方式,都不行,比较菜,哈哈哈。再等等看看有没有做科普的吧,现在用端口转发凑合用了,不做反代了

@bcoderi
Copy link
Author

bcoderi commented Sep 4, 2023

NginxProxyManager的反代搞定了,websocket supports勾选上。原理不懂,反正这么是好用了

家宽:
location /ws { proxy_pass http://192.168.31.99:port/ws; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; proxy_set_header Host $host; proxy_read_timeout 300s; }

个人虚拟服务:
`location / {
proxy_pass http://xxxx.com:port;
proxy_http_version 1.1;
proxy_cache_bypass $http_upgrade;

 proxy_set_header Upgrade            $http_upgrade;
 proxy_set_header Connection         "upgrade";
 proxy_set_header Host                $host;
 proxy_set_header X-Real-IP            $remote_addr;
 proxy_set_header X-Forwarded-For    $proxy_add_x_forwarded_for;
 proxy_set_header X-Forwarded-Proto    $scheme;
 proxy_set_header X-Forwarded-Host    $host;
 proxy_set_header X-Forwarded-Port    $server_port;

}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants