Spring WebSocket:握手因升级头无效而失败:null
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spring WebSocket:握手因升级头无效而失败:null相关的知识,希望对你有一定的参考价值。
我正在使用带有后端弹簧的wss(安全网络套接字)和用于javascript客户端的STOMP。
有谁知道为什么得到:
Handshake failed due to invalid Upgrade header: null
答案
我遇到了与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";
}
}
另一答案
最后,我找到了解决方案。
我不得不在tomcat中打开一个https端口来处理wss请求。
以上是关于Spring WebSocket:握手因升级头无效而失败:null的主要内容,如果未能解决你的问题,请参考以下文章
由于无效的升级标头,Spring Boot Websockets 握手失败:null