Expose SOGo but not Mailcow

1. The problem I’m having:

I recently installed Mailcow and wanted to expose its SOGo interface so that people can connect to their webmail.

However, it’s not working properly:

mail.example.com {
    rewrite * /SOGo{uri}
    reverse_proxy http://192.168.10.10:80
    tls {
        dns cloudflare {env.CF_API_TOKEN}
    }
}

The web UI is broken, there are no CSS, I see some errors in the console related to not loading stuff under /SOGO.woa/… But I don’t know then how to do the rewrite properly then. I don’t know if anyone has experience with it.

3. Caddy version:

v2.8.4 h1:q3pe0wpBj1OcHFZ3n/1nl4V4bxBrYoSoab7rL9BMYNk=

4. How I installed and ran Caddy:

Docker-compose with caddy:2.8.4-builder-alpine

a. System environment:

Unraid 6.12.13

Please fill out the entire help topic template as per the forum rules.

I don’t know anything about Mailcow I can’t really speak to that, but if you can point to specific recommendations from Mailcow for server config, I can help you translate it to Caddy.

2 Likes

I wonder if the blanket rewrite to /SOgo{uri} is doubling up when the upstream app returns a link to /SOgo{uri} (and Caddy then rewrites to /SOgo/SOgo{uri} etc). That would explain the index HTML working but assets being broken.

As a bit of a guessed shot, you could try limiting the rewrite to prevent it from doubling up. Something like:

@not_SOgo not path /SOgo*
rewrite @not_SOgo /SOgo{uri}

Or maybe it even makes more sense to redirect, honestly? Kinda depends.

Other than that, yeah, you’re gonna need to fill out the full template for us to give you better help.

2 Likes

That worked spectacularly. But I still don’t understand why. I will be having a look. Thank you so much.

When you make a request for mail.example.com/ you usually get the index of the webroot /.

With the rewrite you put in, when you request / you actually get the index of /SOgo/ instead.

So imagine your web application serves a file at /SOgo/index.hml. When you request mail.example.com/ you get /SOgo/index.html.

The client requested / but got the contents in the subfolder instead.

Now imagine that index.html file links a /SOgo/style.css document. The browser requested /, got what it assumes is /index.html, and got pointed to /SOgo/style.css.

So your browser makes a request to /SOgo/style.css, but your rewrite doesn’t care that your browser ALREADY requested a /SOgo/ path, your rewrite appends another one. So your browser wants /SOgo/style.css but your server thinks you made a request for /SOgo/SOgo/style.css and your server has no idea what the heck that is. Rinse repeat ad nauseum for all CSS, JS, image etc. assets.

With the check I gave you in place, Caddy now first confirms whether the path already starts with /SOgo and if it does, it won’t bother rewriting, preventing the double-up.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.