我有:
具有mods代理,proxy_http和proxy_wstunnel的Apache 2.4
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName app.test2.fvds.ru
ProxyPass / http://localhost:28080/
ProxyPassReverse / http://localhost:28080/
</VirtualHost>
Wildfly 10在端口28080上
带有websocket的Spring应用程序
Websocket配置:
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.enableSimpleBroker("/response", "/queue");
config.setApplicationDestinationPrefixes("/app");
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry
.addEndpoint("/init")
.setAllowedOrigins("*")
.withSockJS();
}
}
Web.xml:
<!--CORS-->
<filter>
<filter-name>cors</filter-name>
<filter-class>config.CorsFilter</filter-class>
<async-supported>true</async-supported>
</filter>
<filter-mapping>
<filter-name>cors</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
CORS过滤器:
public class CorsFilter implements Filter {
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
//This is not even printing
HttpServletResponse response = (HttpServletResponse) res;
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, UPGRADE");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "x-requested-with, X-Auth-Token, Content-Type");
chain.doFilter(req, res);
}
@Override
public void init(FilterConfig filterConfig) {}
@Override
public void destroy() {}
}
当应用尝试连接时,我收到以下消息:
Failed to load http://app.test2.fvds.ru:28080/init/info:
Redirect from 'http://app.test2.fvds.ru:28080/init/info' to 'http://app.test2.fvds.ru:28080/sign-in'
has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://app.test2.fvds.ru' is therefore not allowed access.
我的代理配置有什么问题?