【发布时间】:2019-01-19 00:04:51
【问题描述】:
我已经研究了RoR 5.0.0 ActionCable wss WebSocket handshake: Unexpected response code: 301 的答案,但不适用于我的情况。
我使用 nginx-proxy 作为在 docker-containers 中运行的多个 Web 服务器的前端。我使用来自https://github.com/jwilder/nginx-proxy的 nginx-config-template
现在在我的 docker-container 中,我有另一个 nginx,其配置如下:
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream websocket {
server my-websocket-docker-container:8080;
}
server {
root /src/html;
location /websocket/ {
resolver 127.0.0.11 ipv6=off;
proxy_pass http://websocket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
location / {
# try to serve file directly, fallback to index.php
try_files $uri /index.php$is_args$args;
}
...
}
当尝试连接到 wss://example.com/websocket 时,我收到上述关于意外响应代码 301 的错误。当我手动 curl websocket-url 时,我可以看到 nginx 响应告诉我“301 永久移动”。但为什么?这是哪里来的?
有人可以帮忙吗?谢谢!
【问题讨论】:
-
您的
location /websocket/有一个尾随/,但您连接到/websocket时没有尾随/。更改任何一个都可能会删除重定向。 -
是的,非常感谢! :-)
-
在我问这个问题之前,我当然尝试添加斜杠,但当时我遇到另一个错误,导致超时 504。哦,周末……
-
如果您想将其作为常规答案发布,我会很乐意支持并接受您的解决方案。谢谢您的帮助! :-)
-
@RichardSmith:你是个摇滚明星。谢谢,就是这样。
标签: nginx websocket nginx-reverse-proxy