How to proxy HTTP and Websockets from Apache to Gunicorn over unix sockets?

862 views Asked by At

My Setup already works over TCP with these two lines in my virtualhost:

ProxyPassMatch ^/ws/.*$ ws://localhost:8000/
ProxyPass / http://localhost:8000/

Now I want to use unix sockets. So I prepended unix:$SOCKETPATH| and removed the port:

ProxyPassMatch ^/ws/.*$ unix:/run/myapp.sock|ws://localhost/
ProxyPass / unix:/run/myapp.sock|http://localhost/

It works for HTTP, but websocket connections fail. I tried variations of the right side in the websockets line, e.g.:

ProxyPassMatch ^/ws/.*$ unix:/run/myapp.sock|ws:///
ProxyPassMatch ^/ws/.*$ unix:/run/myapp.sock|ws://

Besides getting it to work, I'd like to understand why there is the part after the pipe (|) needed anyways? After all, Apache should only need to know the unix socket path, shouldn't it? The Apache documentation on ProxyPass does not explain this.

These similar questions did not help:

1

There are 1 answers

0
Thomas Koch On

I upgraded the Debian Apache packets from 2.4.38-3+deb10u4 (stable) to 2.4.46-4~bpo10+1 (backports) and now it works. The Apache changelog mentions multiple changes to websockets. I suppose this change might have been the problem:

mod_proxy_wstunnel: Leave Upgrade requests handling to mod_proxy_http,
allowing for (non-)Upgrade negotiation with the origin server.