当我在本地网络上托管时,我可以连接可以使用WebSockets的每台设备(包括我的手机)。但是,在AWS上,任何发送HTTP升级请求的客户端都会收到此错误:
if (BS.find('div', {"id" : "table_content"}).h4.find(text=re.compile(".*Super Users.*"))):
print "Found Super Users!"
或
WebSocket connection to 'ws://###.com:8080/###/chat' failed: Connection closed before receiving a handshake response
但是,它适用于Google Chrome。我相信这是因为它至少根据Wireshark所展示的内容不发送升级HTTP请求。
如果有人可以指示我配置错误,那么非常感谢你的到来。
修改 我已经添加了一个NGINX反向代理来获取一些日志
Firefox can’t establish a connection to the server at 'ws://###.com:8080/###/chat'
Google Chrome仍可正常使用:
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream websocket {
server 127.0.0.1:7676;
}
server {
listen 8080 ssl;
location / {
proxy_pass https://websocket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
add_header Strict-Transport-Security "max-age=31536000";
ssl on;
ssl_certificate /home/ubuntu/ssl/cert.crt;
ssl_certificate_key /home/ubuntu/ssl_cert.key;
ssl_prefer_server_ciphers on;
}
其他不起作用的东西给出:
"GET /###/chat HTTP/1.1" 101
答案 0 :(得分:1)
我从ws://
更改为wss://
,现在一切正常。我认为Chrome可能在后台更改了与wss://
的连接。
答案 1 :(得分:0)
我真的不知道NGINX配置,但我看到SSL已被请求,并且您的SSL证书似乎有效(重要!)。 The connection point rule can be summarized as:
和反之亦然:
websocket的圣经 RFC 6455 。在4.1.5节中:
如果/ secure /为true,客户端必须在打开连接之后和发送握手数据之前对连接执行TLS握手[RFC2818]。如果失败(例如,无法验证服务器的证书),则客户端必须使WebSocket连接失败并中止连接。否则,此通道上的所有进一步通信必须通过加密隧道[RFC5246]。
安全标志由URI定义。第3节定义什么是安全
如果方案组件与“wss”不区分大小写,则称为“安全”(并且称“安全标志已设置”)。
<强> TL; DR 强>