Spring WebSocket:握手失败,因为升级标头无效:null
我正在使用wss(安全web套接字)和spring from backend和STOMP for javascript客户端 有人知道为什么会这样吗Spring WebSocket:握手失败,因为升级标头无效:null,spring,websocket,spring-websocket,Spring,Websocket,Spring Websocket,我正在使用wss(安全web套接字)和spring from backend和STOMP for javascript客户端 有人知道为什么会这样吗 Handshake failed due to invalid Upgrade header: null 最后,我找到了解决办法 我必须在tomcat中打开一个https端口来处理wss请求。我在使用到tomcat的nginx https代理时遇到了同样的问题。这是因为我不支持wss请求。为了支持wss请求,我使用如下配置: # WebSocke
Handshake failed due to invalid Upgrade header: null
最后,我找到了解决办法
我必须在tomcat中打开一个https端口来处理wss请求。我在使用到tomcat的nginx https代理时遇到了同样的问题。这是因为我不支持wss请求。为了支持wss请求,我使用如下配置:
# WebSocketSecure SSL Endpoint
#
# The proxy is also an SSL endpoint for WSS and HTTPS connections.
# So the clients can use wss:// connections
# (e.g. from pages served via HTTPS) which work better with broken
# proxy servers, etc.
server {
listen 443;
# host name to respond to
server_name ws.example.com;
# your SSL configuration
ssl on;
ssl_certificate /etc/ssl/localcerts/ws.example.com.bundle.crt;
ssl_certificate_key /etc/ssl/localcerts/ws.example.com.key;
location / {
# switch off logging
access_log off;
# redirect all HTTP traffic to localhost:8080
proxy_pass http://localhost:8080;
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 (nginx 1.4)
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
下面的解决方案适合我
<VirtualHost _default_:443>
ServerName my.app
ServerAdmin admin@my.app
DocumentRoot /var/www/html
SSLCertificateFile ...
SSLCertificateKeyFile ...
SSLCertificateChainFile ...
ProxyPreserveHost on
RequestHeader set X-Forwarded-Proto https
RequestHeader set X-Forwarded-Port 443
RewriteEngine on
RewriteCond %{HTTP:Upgrade}^websocket$ [NC,OR]
RewriteCond %{HTTP:Connection}^upgrade$ [NC]
RewriteRule .* wss:/127.0.0.1:8081%{REQUEST_URI} [P,QSA,L]
RewriteCond %{REQUEST_URI} ^/api/wsendpoint/%{var1}/%{var2}/websocket [NC,OR]
....
</VirtualHost>
ServerName.my.app
服务器管理员admin@my.app
DocumentRoot/var/www/html
SSLCertificateFile。。。
SSLCertificateKeyFile。。。
SSLCertificateChainFile。。。
代理主机
RequestHeader集X-Forwarded-Proto https
RequestHeader集合X转发端口443
重新启动发动机
RewriteCond%{HTTP:Upgrade}^websocket$[NC,或]
RewriteCond%{HTTP:Connection}^升级$[NC]
重写规则。*wss:/127.0.0.1:8081%{REQUEST_URI}[P,QSA,L]
重写cond%{REQUEST_URI}^/api/wsendpoint/%{var1}/%{var2}/websocket[NC,OR]
....
我希望,这有助于。。。
上述解决方案是以下链接的一部分:
您能提供更多细节吗?春季版?您的web配置?你在用sockjs吗?你能复制/粘贴请求和响应的标题吗?你是怎么做到的?你能把解决方案贴出来吗?谢谢嗨,谁能解释一下这个问题吗。我有一个类似的问题,请指导如何解决这个问题。不要告诉我们你已经找到了解决方案,因为我们不在乎。告诉我们如何找到解决方案。@MagnoC“我必须在tomcat中打开一个https端口来处理wss请求。”@mspapant我的服务器已经是纯https(所有http都被重定向)并且没有解决。WSS有特殊端口吗?当所有请求都是https时,我如何在tomcat中打开https端口来处理wss请求呢?看起来我面临着同样的问题。这个配置去哪里了?我面临着同样的问题。但我的URL是ws://localhost:8070/gs-guide-websocket/518/ufd3l0ca/websocket。我已经为ws-request添加了对端口8070的支持。你能帮我@jongou吗对不起,我不记得怎么解决了,很久没有登录stackoverflow了。升级你的nginx和tomcat,也许它可以工作。现在我用的是golang,我没有用tomcat。很抱歉