Question

I have a big problem with websockets and my reverse proxy configuration on Apache. When I access Tomcat directly, the application with websockets works perfectly. But as soon is I try it with Apache, the websockets are not working.

I use:

  • Tomcat 7.0.42 on Windows
  • Apache 2.4.6 on Windows

<VirtualHost _default_:80>
  ServerName myserver

  RewriteEngine on 
  RedirectMatch ^/$ /myserver/ 
  RewriteRule ^/myserver$ /myserver/ [R]
  RewriteRule ^/myserver/active$ /myserver/active/ [R]

  ProxyRequests Off
  ProxyPreserveHost On
  ProxyVia On
  <Proxy *>
   AddDefaultCharset off
   Order deny,allow
   Allow from all
  </Proxy>

  LogLevel debug

  ProxyHTMLEnable On
  ProxyHTMLBufSize  102400
  ProxyHTMLExtended On
  ProxyHTMLStripComments Off
  ProxyHTMLDocType "<!DOCTYPE html>" XML
  ProxyHTMLMeta On

  DocumentRoot "${SRVROOT}/htdocs/"

  <Location /myserver/active/ws/atmsphr/>
    ProxyPass ws://localhost:8080/myapp/ws/atmsphr/
    ProxyPassReverse ws://localhost:8080/myapp/ws/atmsphr/
  </Location>


  ProxyPass /myserver/active/ ajp://localhost:8009/myapp/
  ProxyHTMLURLMap ajp://localhost:8009/myapp /myserver/active/
  <Location /myserver/active/>
   ProxyPassReverse ajp://localhost:8009/myapp/
   SetOutputFilter proxy-html
   ProxyHTMLURLMap /myapp/ /myserver/active/
   ProxyPassReverseCookiePath /myapp/ /myserver/active/
  </Location>

  ProxyPass /myserver/ ajp://localhost:8009/mylogin/
  ProxyHTMLURLMap ajp://localhost:8009/mylogin /myserver/
  <Location /myserver/>
   ProxyPassReverse ajp://localhost:8009/mylogin/
   SetOutputFilter proxy-html
   ProxyHTMLURLMap /mylogin/ /myserver/
   ProxyPassReverseCookiePath /mylogin/ /myserver/
  </Location>
</VirtualHost>

In the Apache logs I can see that the workers were initialized:

[Tue Oct 22 17:25:21.625342 2013] [proxy:debug] [pid 4116:tid 164] proxy_util.c(1693): AH00925: initializing worker ws://localhost:8080/myapp/ws/atmsphr/ shared
[Tue Oct 22 17:25:21.625342 2013] [proxy:debug] [pid 4116:tid 164] proxy_util.c(1733): AH00927: initializing worker ws://localhost:8080/myapp/ws/atmsphr/ local

I followed the Ordering ProxyPass Directives, but the first request is processed by mod_proxy_ajp and not by mod_proxy_wstunnel:

[Tue Oct 22 17:26:19.283043 2013] [proxy_http:debug] [pid 4116:tid 840] mod_proxy_http.c(1891): [client 192.168.5.68:49451] AH01113: HTTP: declining URL ajp://localhost:8009/myapp/websock/atmsphr?X-Atmosphere-tracking-id=0&X-Atmosphere-Framework=2.0.2-jquery&X-Atmosphere-Transport=websocket&X-Atmosphere-TrackMessageSize=true&X-Cache-Date=0&Content-Type=application/json&X-atmo-protocol=true                     
[Tue Oct 22 17:26:19.283043 2013] [proxy_ajp:debug] [pid 4116:tid 840] mod_proxy_ajp.c(713): [client 192.168.5.68:49451] AH00895: serving URL ajp://localhost:8009/myapp/ws/atmsphr?X-Atmosphere-tracking-id=0&X-Atmosphere-Framework=2.0.2-jquery&X-Atmosphere-Transport=websocket&X-Atmosphere-TrackMessageSize=true&X-Cache-Date=0&Content-Type=application/json&X-atmo-protocol=true

What is wrong in my configuration?

Was it helpful?

Solution

After a long research I found a workaround which fullfills my requirements. I've to run this webapplication via HTTPS and with port 443 it works perfectly. I can not explain why there is a problem with the default HTTP port 80, but if I access the webapp through port 443 there is no problem. In addition i tried port 8000 via HTTP und it also works.

Summary:

Port 80 / HTTP  --> not working
Port 8000 / HTTP --> working
Port 443 / HTTPS --> working

In conclusion I have an virtual host config for port 80 with a permanent redirct to 443.

OTHER TIPS

It has to do with the effective order of your ProxyPass directives. Have a look at the server-status page to see what it really is. When you embed them in Location blocks the effective order is changed from the order you wrote them in. See the mod_proxy_wstunnel documentation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top