Configure Apache + Tomcat with Websocket capability

If you configure Apache httpd server and Tomcat server together, you usually use Tomcat connect(AJP) to hook up both of them. Http requests and responses are transferred through the AJP tunnel. AJP works well on HTTP protocols. However, if you have to invoke websocket calls(ws://, AJP fails to complete it.

To resolve it, we configure wstunnel between Apache httpd and Tomcat.

Here we take httpd-2.4.25 as an sample.

Step 1. Prepare file
By default, Apache HTTPD doesn’t provide file(/usr/local/apache-2.4.25/modules/ We have to build it ourselves.
Download httpd-2.4.25 and uncompress it.

cd /aaa/bbb/httpd-2.4.25-src
./configure --prefix=/usr/local/apache-2.4.25 --enable-mods-shared=all --enable-so --enable-proxy=shared --enable-proxy-wstunnel
make install

–enable-proxy=shared –enable-proxy-wstunnel will generate file.

Step 2. Modify httpd.conf
Edit /usr/local/apache-2.4.25/conf/httpd.conf

LoadModule proxy_module modules/
LoadModule proxy_wstunnel_module modules/

Step 3. Set proxy rule
Based on your requirement, edit httpd.conf or httpd-vhosts.conf
If pointing to localhost, add

ProxyPass /websocket/ ws://localhost:8080/websocket/
ProxyPassReverse /websocket/ ws://localhost:8080/websocket/

Notice. In Tomcat server.xml, there must be a connector defined as port=”8080″ protocol=”HTTP/1.1″

If pointing to another host, add

ProxyPass /websocket/ ws://
ProxyPassReverse /websocket/ ws://

Step 4. Restart httpd server


Leave a Reply

Your email address will not be published. Required fields are marked *