我有以下问题:
我需要将服务器及其应用程序容器化。我有一个nginx代理,nginx网站,mysql和一个运行应用程序的带有springboot的容器。该服务器可通过我们网络中的DNS条目从外部访问,并具有https证书。
当我在服务器上运行它时,我可以连接websocket。
有了这些容器,我只会收到301错误,或者在浏览器中看到“只能“升级”到“ WebSocket”。信息。所有这些都以docker-compose开始。当我直接测试Websocket与IP(甚至是名称)的连接时,我得到了想要的结果。
这是我在nginx conf中配置websocket(端口8090,因为那是应用程序运行的地方,并且它可以通过其他方式工作,请参见上文)
server {
server_name some.website.com;
location /websocket {
proxy_pass http://appcontainername:8090/websocket;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# WebSocket support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
...
}
这就是我对some.website.com进行测试的结果:
HTTP/1.1 301 Moved Permanently
Server: nginx/1.14.0 (Ubuntu)
Date: Wed, 31 Jul 2019 08:54:48 GMT
Content-Type: text/html
Content-Length: 194
Connection: keep-alive
Location: https://kls-sb.engram.de/websocket
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.14.0 (Ubuntu)</center>
</body>
</html>
这就是我直接对应用程序容器进行测试的结果:
HTTP/1.1 101
Set-Cookie: JSESSIONID=46A159F2DE610889B24C4F3B649D5A15; Path=/; HttpOnly
Upgrade: websocket
Connection: upgrade
Sec-WebSocket-Accept: vtdlO0Wwuk/ntwKFymxq9rTd25Q=
ETag: "0d41d8cd98f00b204e9800998ecf8427e"
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: DENY
Date: Wed, 31 Jul 2019 08:55:00 GMT
我对此进行测试:
curl -i -N -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Host: some.website.com" -H "Origin: http://some.website.com" -H "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" -H "Sec-WebSocket-Version: 13" http://some.website.com/websocket (or http://IP.of.container:8090/websocket)
有人知道我如何从中获得“ Websocket:升级”吗?
谢谢!