TransWikia.com

Servicing ws:// in Node.js via Tomcat and Apache

Server Fault Asked by Ken Y-N on November 23, 2020

I’ve Googled various combinations of keywords but I cannot find a suitable description of what to do to get this to work. Currently, I have a web site running Apache 2 with everything except ports 80 and 443 blocked. I’ve set up Tomcat to route through :80 and :443 using:

<Location /tomcat/>
ProxyPass ajp://localhost:8009/tomcat/
Order allow,deny
Allow from all
</Location>

Furthermore, existing Node.js http[s] apps have also been successfully routed via code like this:

<Location /app_8201/>
ProxyPass http://localhost:8201/
</Location>

I’m running Apache/2.2.15, Tomcat 6 and Node.js v0.10.26 on CentOS under Azure. Websocket support is present as running sample apps referring localhost:9999 works OK. There looks as if there should be a ProxyPass ws://localhost:9999, but if I follow the instructions here:

<Location /ws/>
ProxyPass http://localhost:9999
ProxyPassReverse http://localhost:9999
</Location>

I get an HTTP 500 error trying to access the directory ws by either http or ws.

I use mod_proxy_ajp instead of mod_jk as it is my understanding the ajp is “better”.

One Answer

WebSocket support first appeared in Apache 2.4.5 through the mod_proxy_wstunnel module, there is no support in previous versions like Apache 2.2.

The protocol must be explicitly selected via ws:// or wss://, the AJP and HTTP protocol modules for mod_proxy don't know anything about WebSockets:

<Location /ws>
    ProxyPass ws://localhost:9999
    ProxyPassReverse ws://localhost:9999
</Location>

Answered by PeterPramb on November 23, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP