我的应用程序在Spring Framework中使用SockJS。我的服务器上有一个反向代理,用于将https请求重定向到tomcat容器。配置:
<VirtualHost *:443>
ProxyPreserveHost On
ProxyPass /boot http://127.0.0.1:8080/boot/
ProxyPassReverse /boot http://127.0.0.1:8080/boot/
ServerName MY_DOMAIN.com
SSLEngine on
SSLProtocol all
SSLCertificateFile /etc/apache2/ssl/muhamo.crt
SSLCertificateKeyFile /etc/apache2/ssl/muhamo.key
SSLCACertificateFile /etc/apache2/ssl/bundl.crt
</VirtualHost>
如何配置虚拟主机以将wss请求转发给我的应用程序?我收到如下错误消息:
Opening Web Socket...
sockjs.js:1213 WebSocket connection to 'wss://MY_DOMAIN.com/boot/tracking/557/jcf7btih/websocket' failed: Error during WebSocket handshake: Unexpected response code: 403
sockjs.js:807 POST https://MY_DOMAIN.com/boot/tracking/557/7cl9qov2/xhr_streaming 403 (Forbidden)
sockjs.js:807 POST https://MY_DOMAIN.com/boot/tracking/557/cvl8ti6k/xhr 403 (Forbidden)
答案 0 :(得分:7)
我不知道你是否解决了这个问题,但我遇到了同样的问题。 我认为问题出在apache服务器上,但它是在Spring端。 403代码是线索。
在我的情况下,除了您的配置(进行必要的调整)之外,我所做的是添加以下内容:
# Disable forward proxying
ProxyRequests Off
# proxy wss:// to ws://
ProxyPassMatch ^/(.*)/websocket ws://localhost:8080/$1/websocket
# proxy ws fallbacks
ProxyPass /ws http://localhost:8080/ws
ProxyPassReverse /ws http://localhost:8080/ws
在Spring(引导)方面:
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.enableSimpleBroker("/topic");
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/ws").setAllowedOrigins("*").withSockJS();
}
}
setAllowedOrigins("*")
是克服403错误的缺失部分。
干杯