0

I have a server which currently redirects everything to a web app running in a docker container on the same machine.

I would like to direct urls beginning /mail to an instance of mailcatcher running in another docker container.

[This post editied to add new stuff I have tried] I got so far with

ServerName myserver.uk
ServerAlias www.myserver.uk
ServerAdmin serveradmin@protonmail.com
ProxyPreserveHost On

# My attempts to get MailCatcher working
# Rewrite rules are a complete mystery to me, I'm just taking these from one of the tutorials I have found
# Every tutorial seems to do it differently, which is confusing!
# Is websocket some magic keyword?
RewriteEngine on
RewriteCond ${HTTP:Upgrade} websocket [NC]
RewriteCond ${HTTP:Connection} upgrade [NC]
RewriteRule .* "wss:/localhost:1080/$1" [P,L]
ProxyPassMatch (.*)(\/websocket)$ "ws://127.0.0.1:1080/$1$2"
ProxyPass /assets/ http://localhost:1080/assets/
ProxyPassReverse /assets/ http://localhost:1080/assets/
ProxyPass /messages/ http://localhost:1080/messages/
ProxyPassReverse /messages/ http://localhost:1080/messages/
ProxyPass /mail/ http://localhost:1080/
ProxyPassReverse /mail/ http://localhost:1080/

# The main web app
ProxyPass / http://localhost:8090/
ProxyPassReverse / http://localhost:8090/

but I discover mailcatcher uses Web Sockets. If I run a console window in by browser, I see:

GET https://myserver.uk/messages 404 (Not Found)
mailcatcher.js:5 WebSocket connection to 'wss://myserver/messages' failed: Error during WebSocket handshake: Unexpected response code: 404

I am obviously missing something - what should I change in my apache configuration?

Nikki Locke
  • 171
  • 2
  • 9
  • A simple search for "apache proxy websocket" shows a lot of other Apache configurations for other applications that use websockets. It should be trivial to adapt it to this case. And please, get the terminology straight. You are not doing any redirects here, this is just a reverse proxy, nothing else. – Gerald Schneider Jul 06 '20 at 13:34
  • Sorry to have upset you. I have searched for something similar that, and every hit I find tells me to do something different, and none of the 10 or so I have read so far deal with the situation where most requests go to one proxy server, and a few go to another. Plus they all use mod_rewrite in ways that seem to be completely undocumented (what does `${HTTP:Upgrade}` mean?). – Nikki Locke Jul 06 '20 at 14:54

1 Answers1

1

I gave up in the end, and created a new domain name to just do the MailCatcher stuff. My conf file ended up as:

<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerName mc.myserver.uk
        ServerAdmin mcadmin@protonmail.com
        ProxyPreserveHost On
        ProxyRequests On
        ProxyPass /messages/ ws://localhost:1080/messages/
        ProxyPassReverse /messages/ http://localhost:1080/messages/
        ProxyPass / http://localhost:1080/
        ProxyPassReverse / http://localhost:1080/
        RequestHeader set X-Forwarded-Proto "https"

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        <Location />
                AuthType Basic
                AuthName "Authentication Required"
                AuthUserFile "/etc/htpasswd/.htpasswd"
                Require valid-user
                Order allow,deny
                Allow from all
        </Location>

SSLCertificateFile /etc/letsencrypt/live/mc.myserver.uk/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mc.myserver.uk/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

Unfortunately that works only up to a point - it displays the main screen, and the message list, but any attempt to display a message fails with a 500 server error.

Nikki Locke
  • 171
  • 2
  • 9