How to configure Apache for Phoenix?

Hello everyone!

I am trying to configure apache so I can have my Phoenix-Elixir-application running on the same server as some other applications.

The basic request-passing works, but I am having problems with the websocket-connections:

<VirtualHost *:80>
        DocumentRoot "/var/www/my_app"
        ServerName my_app.tld
        ServerAlias www.my_app.tld

        LoadModule proxy_module modules/
        ProxyRequests Off
        ProxyPreserveHost On
        ProxyPass "/" "ws://localhost:4096/" retry=0 timeout=5
        ProxyPassReverse "/" "ws://localhost:4096/" my_app.tld 

However, this does not properly work. The websocket connections fail, with the following response in the browser console:

WebSocket connection to 'ws://my_app.tld/socket/websocket?vsn=2.0.0' failed: Error during WebSocket handshake: Unexpected response code: 400

I don’t know what went wrong, but also not how to debug this: Nothing can be found in the apache log, nor in the Phoenix application log.

1 Like

We just had the similar issue opened with Drab, please take a look. Guido resolved it himself, and also wrote the wiki page about it.


Thank you, @grych! The proposed solution there (to add first a set of aliases for /socket/ besides the global ones) indeed seem to work, although I still need to check if this will still allow the fallback behaviour (that uses long-polling rather than websockets for the channel-connections) to work, because my intuition tells me that maybe apache will now also redirect HTTP requests to /socket/ to a websocket connection.

Thanks! :heart: