Mailcow-dockerized: adding an subdomain for Sogo (nginx reverse proxy)

Created on 20 May 2018  路  20Comments  路  Source: mailcow/mailcow-dockerized

Everthing works like a charm. I set up a new vps, installed nginx, than docker and than mailcow. I use the ssl certificates from mailcow for the reverse proxy - everything fine!

but it is possible to use another domain for sogo? I tried a new nginx config file for sogo.domain.tld and tried to point to sogo:

location / {
    proxy_pass http://127.0.0.1:8080/SoGo/;
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    client_max_body_size 100m;

..

But it doesnt work, I just got a 404 Error

Would be happy for any help :)

Most helpful comment

This works for me. I had to use a rewrite not a redirect, but works smoothly. The rewrite rule simple changes "/" to "/SOGo".

 location / {
      rewrite ^/$ /SOGo;
      proxy_pass http://127.0.0.1:8080;
      proxy_set_header Host $http_host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      client_max_body_size 100m;
 }

If you want to see my full setup with a reverse proxy, check out my gists. Hope this helps you, I just figured this out myself and so far haven't run into any problems but I welcome opinions since I'm still learning.

All 20 comments

location / {
    proxy_pass http://127.0.0.1:8080/SOGo/;
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    client_max_body_size 100m;
}

Could you please try that?

Best Regards
Tom Siewert

thanks, but it's actually what I've tried before, ...

Please look at the URL. You wrote SoGo, but it is SOGo.

Sorry, didn't notice, but doesn't change anything 馃

Could you please run curl -I http://127.0.0.1:8080/SOGo and send us the result?

Hey guys, here is the output:

root@r3v:~# curl -I http://127.0.0.1:8080/SOGo
HTTP/1.1 302 Found
Server: nginx
Date: Mon, 21 May 2018 19:29:02 GMT
Content-Type: text/plain
Content-Length: 0
Connection: keep-alive
Location: /SOGo/index
Strict-Transport-Security: max-age=15768000; includeSubDomains
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
X-Robots-Tag: none
X-Download-Options: noopen
X-Permitted-Cross-Domain-Policies: none

And I will add one screen as well. the site load, but it seems like css, pictures and anything else doesnt load.

sogofail

Is the screenshot from your subdomain, or from your main domain (mx01.domain.tld/SOGo)?

From sogo.domain.tld. From mail.domain.tld/SOGo, everything works like a charm 馃槉

@gxf0 We've been discussing this since a long time ago with no good results. For now this thread https://github.com/mailcow/mailcow-dockerized/issues/393 is the most well documented -nearest- workaround for what you want, also there's a config file that I've post to start to play with, sadly this is "test and fail" method.

Sorry to tell you that this has not been achieved yet.

thanks a lot, I give up- haha. Is not that important. I will just use a 301 redirect

server {
    listen 80;
    listen 443 ssl http2;
    index index.php index.html index.htm;
    server_name sogo.domain.tld; 

    location / {
    return 301 https://mail.domain.tld/SOGo$request_uri;
    }
}

but I really would like to at least use the reverse proxy for the nextcloud setup. Is this possible? I tried all kind of way, but it faild multimple times :/

This works for me. I had to use a rewrite not a redirect, but works smoothly. The rewrite rule simple changes "/" to "/SOGo".

 location / {
      rewrite ^/$ /SOGo;
      proxy_pass http://127.0.0.1:8080;
      proxy_set_header Host $http_host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      client_max_body_size 100m;
 }

If you want to see my full setup with a reverse proxy, check out my gists. Hope this helps you, I just figured this out myself and so far haven't run into any problems but I welcome opinions since I'm still learning.

thanks a lot man, this not really solve the subdomain problem totaly, but its a nice work around to use a differen subdomain :)

I will check out your gists

What issue is it not solving for you? Maybe I can help you out?

So @asifbacchus solution is working fine for me. Is there any alternative for removing /SOGo in the subdomain? It would be nice to have only webmail.example.com.

With the rewrite, you shouldn't ever have to type /SOGo again... but if you mean actually getting rid of the subdirectory, I don't think that's (easily) possible. I know SOGo itself, as a raw install, requires that subdirectory in the domain. So you'd have to set up a bunch of redirects -- a reverse proxy, in this case, is just easier. I don't know if that helped answer your question?

Yeah I was talking about getting rid of /SOGo subdirectory. Doesn't seem reasonable to get rid of it if it requires a lot of stuff to be done on the reverse proxy. Thanks for your help.

I don't think it's possible, because of how SOGo is designed. Glad I could help you out though.

Ah okay, thanks for the infos. If SoGo relies on the subdirectory I guess it's okay. Don't want to reconfigure any small thing through reverse proxy - too much work and to big chance to screw it up.

I guess I will go with @asifbacchus rewrite methode - good enough for me.

Thank you guys for all your input! I will close the topic :)

Ok, I found a solution without a rewrite and without any subdirectories or something.
This is my nginx block:

location / {
                #rewrite ^/$ /SOGo;
                proxy_http_version 1.1;
                proxy_set_header Host $http_host;
                proxy_set_header Referer $http_referer;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto https;
                proxy_set_header X-Forwarded-Ssl on;
                #proxy_set_header X-Nginx-Proxy true;
                proxy_set_header X-Client-Verify $ssl_client_verify;
                proxy_set_header X-Client-DN $ssl_client_s_dn;
                proxy_set_header X-SSL-Issuer $ssl_client_i_dn;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                proxy_pass http://172.22.1.11:1380/SOGo/SOGo/;
        }

I came to this solution, because I am using pihole which has a similar issue, because it only works if you append /admin to the proxy_pass like this: proxy_pass http://172.20.0.2/admin/;
EDIT: This is only working if you set the hostname in mailcow.conf to "domain.com", not to "mail.domain.com". Otherwwise you do not get the wanted page...

Thanks for sharing! But seems like also not working for me. I guess I will have to check it, when I have a little bit more time 馃槉

Was this page helpful?
0 / 5 - 0 ratings

Related issues

a3li picture a3li  路  3Comments

lgleim picture lgleim  路  3Comments

poldixd picture poldixd  路  3Comments

constin picture constin  路  3Comments

damdinsharav picture damdinsharav  路  3Comments