Spring WebSocket : Handshake failed due to invalid Upgrade header: null

标签 spring websocket spring-websocket

我正在使用带有来自后端的 spring 的 wss(安全 Web 套接字)和用于 javascript 客户端的 STOMP。

有谁知道为什么会得到:

Handshake failed due to invalid Upgrade header: null

最佳答案

我在使用 nginx https 代理到 tomcat 时遇到了同样的问题。这是因为我不支持 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";
    }
}

关于Spring WebSocket : Handshake failed due to invalid Upgrade header: null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31211919/

相关文章:

java.lang.NoClassDefFoundError : org/apache/http/impl/conn/PoolingClientConnectionManager 错误

Java:我无法使用 CRUD 存储库 deleteByID() 从我的实体中删除实例

javascript - 强制 javascript 代码同步

java - Spring Boot websocket握手间歇性挂起

java - Spring Boot - 需要哪些注解

spring - 为什么 @MockBean 和 @InjectMocks 导致 BeanCreationException?

javascript - 正在发送 Socket.io 额外占位符帧

angularjs - 如何使用 Websockets 更新 REST API 请求状态

java - Spring 中的其他 WebsocketClient 实现是什么?

java - Spring websocket STOMP 取消订阅 eventHandler