Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache proxyPassReverse and Websockets

I've been working on a Perl Mojolicious project that uses websockets. I'm wanting to launch it on a shared server running apache and use proxyPass and proxyPassReverse to make the url prettier for my Mojolicious code running with Hypnotoad.

I have it set up as follows.

Apache url:

mydomain.com

Hypnotoad url:

mydomain.com:8080

With the following apache entry I can reverse proxy the Hypnotoad server to

project.mydomain.com

apache.conf entry

<VirtualHost *:80>
  ServerName project.mydomain.com
  DocumentRoot /var/www/project
  <Directory /var/www/project/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
  </Directory>
  ProxyRequests Off
  ProxyPreserveHost On
  ProxyPass / http://mydomain.com:8080/ keepalive=On
  ProxyPassReverse / http://mydomain.com:8080/
  RequestHeader set X-Forwarded-HTTPS "0"
</VirtualHost>

However my websocket requests give a 404 error when I use:

ws://project.mydomain.com/get-data

and a 302 error when I use:

ws://mydomain.com:8080/get-data

I guess this wouldn't be a problem is the websocket didn't check for authentication, but they use Mojolicious routes to check that you can post via the websocket.

From what I can see Apache doesn't support reverse proxying websockets. In apache/httpd conf files.

Has anyone found a usable solution to this using Apache that is stable for a production environment?

like image 793
user1439590 Avatar asked Jan 22 '13 06:01

user1439590


People also ask

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.

Do Websockets work through reverse proxy?

WebSocket over a Reverse Proxy. WebSocket communication can take place over any reverse proxy which is configured to perform forwarding at the transport layer. Some proxies are able to handle WebSocket communication from certain clients at the application layer.

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.

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. This page explains how to configure a Universal Messaging JavaScript client and Apache serving as a forward proxy to permit WebSocket use.


1 Answers

In March a patch was committed to the Apache trunk by Jim Jagielski which allows websockets to be proxied correctly. The patch adds a new submodule called proxy_wstunnel which allows mod_proxy to work with the "ws" and "wss" protocols.

The module is not yet in any official Apache releases (as of June 8th 2013), so you will need to compile it yourself. Voyageur's blog describes the process for Apache 2.2, but it should be easier for Apache 2.4

like image 97
rmeakins Avatar answered Oct 20 '22 22:10

rmeakins