WebSockets through Apache and Tomcat: HTTP upgrade is not supported by the AJP protocol

跟風遠走 提交于 2019-12-08 17:57:49

问题


I am developing with WebSockets, and made a working web application running on Tomcat 8. However, when testing with Apache 2 in front of it, the client is getting an HTTP 500 and the Tomcat log says:

 java.lang.UnsupportedOperationException: HTTP upgrade is not supported by the AJP protocol
    at org.apache.coyote.ajp.AbstractAjpProcessor.action(AbstractAjpProcessor.java:587)
    at org.apache.coyote.Request.action(Request.java:379)
    at org.apache.catalina.connector.Request.upgrade(Request.java:1886)
    at org.apache.catalina.connector.RequestFacade.upgrade(RequestFacade.java:1114)
    at org.apache.tomcat.websocket.server.UpgradeUtil.doUpgrade(UpgradeUtil.java:231)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:77)

This worked when accessing Tomcat directly through its HTTP connector. If this is not supported with AJP, is there a workaround?


回答1:


Use Apache module mod_proxy_wstunnel:

sudo a2enmod mod_proxy_wstunnel

Then use it to let WebSocket connections through by adding this to apache.conf:

ProxyPass "/ws2/"  "ws://localhost:8180/ws"

And make sure you have enabled an HTTP connector in Tomcat by using <Connector protocol="HTTP/1.1" port="8180" ...> in server.xml.



来源:https://stackoverflow.com/questions/30667429/websockets-through-apache-and-tomcat-http-upgrade-is-not-supported-by-the-ajp-p

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!