Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reverse proxy with websocket mod_proxy_wstunnel

I have a problem with the web sockets and my reverse proxy Apache, I have upgraded in latest release 2.4.5 and loaded the module mod_proxy_wstunnel.

The httpd.conf :

<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName www.toto.fr
ServerAlias toto.fr


ProxyPass /my_app  http://1X.X.X.1:8080/my_app
ProxyPassReverse /web_pmr  http://1X.X.X.1:8080/my_app
ProxyPassReverseCookiePath /my_app /
ProxyPassReverseCookieDomain localhost my_app
ProxyRequests off
ProxyTimeout 15

#WEBSOCKETS


ProxyPass /my_app/BasicWebsocketServlet ws://1X.X.X.1:8080/my_app/BasicWebsocketServlet retry=0
ProxyPassReverse /my_app/BasicWebsocketServlet ws://1X.X.X.1:8080/web_pmr/BasicWebsocketServlet retry=0


ErrorLog "logs/my_app_error.log"
LogLevel debug
CustomLog "logs/my_app_access.log" combined
<Proxy *>
      Order deny,allow
      Allow from all
</Proxy>
</VirtualHost>

When I test in my local URL, websockets are working but with the reverse proxy Apache, there is no trace in Tomcat logs.

like image 789
WhatsUp Avatar asked Jul 15 '13 07:07

WhatsUp


People also ask

Do proxies support WebSockets?

Today, most transparent proxy servers will not yet be familiar with the Web Socket protocol and these proxy servers will be unable to support the Web Socket protocol. In the future, however, proxy servers will likely become Web Sockets-aware and able to properly handle and forward WebSocket traffic.

What is WebSocket reverse proxy?

A reverse HTTP proxy over WebSocket is a type of proxies, which retrieves resources on behalf on a client from servers and uses the WebSocket protocol as a "tunnel" to pass TCP communication from server to client.

Can WebSocket be proxied?

WebSocket communication can take successfully take place in the presence of forward proxies, providing the client and proxy server have been configured properly to deal with it.

Does Apache support WebSockets?

The new version 2.4 of Apache HTTP Server has a module called mod_proxy_wstunnel which is a websocket proxy.


1 Answers

This line:

ProxyPass /my_app/BasicWebsocketServlet ws://1X.X.X.1:8080/my_app/BasicWebsocketServlet retry=0

needs to come before this one:

ProxyPass /my_app  http://1X.X.X.1:8080/my_app

Explanation (from https://httpd.apache.org/docs/2.4/mod/mod_proxy.html#proxypass):

Ordering ProxyPass Directives

The configured ProxyPass and ProxyPassMatch rules are checked in the order of configuration. The first rule that matches wins. So usually you should sort conflicting ProxyPass rules starting with the longest URLs first. Otherwise later rules for longer URLS will be hidden by any earlier rule which uses a leading substring of the URL. Note that there is some relation with worker sharing. In contrast, only one ProxyPass directive can be placed in a Location block, and the most specific location will take precedence.

For the same reasons exclusions must come before the general ProxyPass directives.

like image 193
hdgarrood Avatar answered Oct 05 '22 03:10

hdgarrood