我正在尝试将 nginx 配置为执行身份验证和 websockets 的反向代理。它代理将请求传递给 apache (/auth/wsgi) 以进行身份验证 - 一旦成功,它就会将代理传递给 websocked 后端,这是在 tomcat 8 上基于 Java 的 websocket 端点。
location /basic/alerting/websocket {
auth_request /auth/wsgi;
proxy_pass http://backend.com:8080/websocket;
proxy_http_version 1.1;
proxy_set_header Upgrade "Websocket";
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
}
Run Code Online (Sandbox Code Playgroud)
apache 认证成功。但是,在后端 tomcat 上,我收到此错误:
12572237 [http-nio-8080-exec-10] 错误 org.springframework.web.socket.server.support.DefaultHandshakeHandler - handleWebSocketVersionNotSupported() 由于不支持的 WebSocket 版本,握手失败:null。支持的版本:[13]
失败似乎是因为后端期望没有通过的标头(“Sec-WebSocket-Version”)。我什至在 nginx 日志中看到:
2015/03/17 17:28:12 [调试] 20261#0:*718 http 代理标头:“Sec-WebSocket-Version: 13”
我需要在 nginx 配置中做什么吗?非常感谢您的帮助。