Mailcow-dockerized: How to run mailcow behind the nginx-proxy?

Created on 6 Jan 2020  Â·  11Comments  Â·  Source: mailcow/mailcow-dockerized

I want to run mailcow behind reverse proxy from this repo:
https://github.com/jwilder/nginx-proxy
Also, want to run it on SSL via:
https://github.com/JrCs/docker-letsencrypt-nginx-proxy-companion
But, not getting that what exactly I should do and which ports should I expose.
I've searched a lot but couldn't get a satisfactory result to my search.
Need the guidance in accomplishing this.
I already have many applications running successfully via nginx-proxy but not getting this one due to it's complexity.
Any help will be highly valuable.

support

Most helpful comment

first of all, jwilder's nginx proxy yaml:

version: '2'

services:
  https-proxy:
    image: jwilder/nginx-proxy
    container_name: https-proxy
    restart: always
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro
      - ${PWD}/vhost.d:/etc/nginx/vhost.d
      - ${PWD}/html:/usr/share/nginx/html
      - ${PWD}/certs:/etc/nginx/certs
      - ${PWD}/uploadsize.conf:/etc/nginx/conf.d/uploadsize.conf
    networks:
      - front

  letsencrypt-nginx-proxy-companion:
    image: jrcs/letsencrypt-nginx-proxy-companion
    container_name: letsencrypt
    environment:
      - "[email protected]"
    restart: always
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    volumes_from:
      - https-proxy
    networks:
      - front

networks:
  front:
    external:
      name: https-proxy`

mailcow yaml (I have shown you only the parts you need to edit - compare it with your yaml file):

   nginx-mailcow:
      depends_on:
        - sogo-mailcow
        - php-fpm-mailcow
        - redis-mailcow
      image: nginx:mainline-alpine
      dns:
        - ${IPV4_NETWORK:-172.22.1}.254
      command: /bin/sh -c "envsubst < /etc/nginx/conf.d/templates/listen_plain.template > /etc/nginx/conf.d/listen_plain.active &&
        envsubst < /etc/nginx/conf.d/templates/listen_ssl.template > /etc/nginx/conf.d/listen_ssl.active &&
        envsubst < /etc/nginx/conf.d/templates/server_name.template > /etc/nginx/conf.d/server_name.active &&
        envsubst < /etc/nginx/conf.d/templates/sogo.template > /etc/nginx/conf.d/sogo.active &&
        envsubst < /etc/nginx/conf.d/templates/sogo_eas.template > /etc/nginx/conf.d/sogo_eas.active &&
        . /etc/nginx/conf.d/templates/sogo.auth_request.template.sh > /etc/nginx/conf.d/sogo_proxy_auth.active &&
        . /etc/nginx/conf.d/templates/sites.template.sh > /etc/nginx/conf.d/sites.active &&
        nginx -qt &&
        until ping phpfpm -c1 > /dev/null; do sleep 1; done &&
        until ping sogo -c1 > /dev/null; do sleep 1; done &&
        until ping redis -c1 > /dev/null; do sleep 1; done &&
        until ping rspamd -c1 > /dev/null; do sleep 1; done &&
        exec nginx -g 'daemon off;'"
      environment:
        - HTTPS_PORT=${HTTPS_PORT:-443}
        - HTTP_PORT=${HTTP_PORT:-80}
        - MAILCOW_HOSTNAME=${MAILCOW_HOSTNAME}
        - IPV4_NETWORK=${IPV4_NETWORK:-172.22.1}
        - TZ=${TZ}
        - ALLOW_ADMIN_EMAIL_LOGIN=${ALLOW_ADMIN_EMAIL_LOGIN:-n}
        - VIRTUAL_HOST=mail.yourdomain.com
        - LETSENCRYPT_HOST=mail.yourdomain.com
      volumes:
        - ./data/web:/web:ro
        - ./data/conf/rspamd/dynmaps:/dynmaps:ro
        - ./data/assets/ssl/:/etc/ssl/mail/:ro
        - ./data/conf/nginx/:/etc/nginx/conf.d/:rw
        - ./data/conf/rspamd/meta_exporter:/meta_exporter:ro
        - sogo-web-vol-1:/usr/lib/GNUstep/SOGo/
      restart: always
      networks:
        mailcow-network:
          aliases:
            - nginx
        proxy:

networks:
  proxy:
    external:
      name: https-proxy
  mailcow-network:
    driver: bridge
    driver_opts:
      com.docker.network.bridge.name: br-mailcow
      com.docker.network.driver.mtu: 1450 
    enable_ipv6: false
    ipam:
      driver: default
      config:
        - subnet: ${IPV4_NETWORK:-172.22.1}.0/24
        - subnet: ${IPV6_NETWORK:-fd4d:6169:6c63:6f77::/64}

this is how it's in my configs. as you can see there is not that much hassle to get it working.

you also need to create a network (prior to running containers) in docker as I did (https-proxy). docker-compose won't create it for you. docker network create https-proxy
you can also add roundcube to mailcows yaml. if there is a need I will post my config in my repo

All 11 comments

@andryyy can you please help on this?

Your best option is to join the telegram channel or wait for someone who actually uses the proxy. Highlight someone from the other issues. :)

I wrote a rough guide in the netcup forum some time ago:
https://forum.netcup.de/administration-eines-server-vserver/vserver-server-kvm-server/p121991-docker-mailcow-nginx-reverse-proxy-wordpress/#post121991

Hmu if you need more information. Might write a more specific blog post in the future.

it's quite easy once you've spent countless hours on tinkering with docker... but here is what I did.

jwilder's nginx should be set up just like its wiki says it should be. I'm not touching that subject here.

in mailcow's docker-compose you have to comment out some lines and add two lines:

in nginx-mailcow services' environment variables add:

  • LETSENCRYPT_HOST=
  • VIRTUAL_HOST=

and comment out whole ports: section. you can even delete it

Once you have done it run docker-compose up -d in mailcow's directory. jwilder's container should pick it up and pull cert's, create conf and voila. that is all

You can override/add the variables with a docker-compose.override.yml file. :)

Thanks for your feedback.

I wrote a rough guide in the netcup forum some time ago:
https://forum.netcup.de/administration-eines-server-vserver/vserver-server-kvm-server/p121991-docker-mailcow-nginx-reverse-proxy-wordpress/#post121991

Hmu if you need more information. Might write a more specific blog post in the future.

Could u make a detailed guide? I’m getting tired after a few days of trying....

it's quite easy once you've spent countless hours on tinkering with docker... but here is what I did.

jwilder's nginx should be set up just like its wiki says it should be. I'm not touching that subject here.

in mailcow's docker-compose you have to comment out some lines and add two lines:

in nginx-mailcow services' environment variables add:

  • LETSENCRYPT_HOST=
  • VIRTUAL_HOST=

and comment out whole ports: section. you can even delete it

Once you have done it run docker-compose up -d in mailcow's directory. jwilder's container should pick it up and pull cert's, create conf and voila. that is all

Wich lines do you got any specific guide or config files?

Could u make a detailed guide? I’m getting tired after a few days of trying....

The post pretty much covers everything you have to add or comment out. What's not working atm?

first of all, jwilder's nginx proxy yaml:

version: '2'

services:
  https-proxy:
    image: jwilder/nginx-proxy
    container_name: https-proxy
    restart: always
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro
      - ${PWD}/vhost.d:/etc/nginx/vhost.d
      - ${PWD}/html:/usr/share/nginx/html
      - ${PWD}/certs:/etc/nginx/certs
      - ${PWD}/uploadsize.conf:/etc/nginx/conf.d/uploadsize.conf
    networks:
      - front

  letsencrypt-nginx-proxy-companion:
    image: jrcs/letsencrypt-nginx-proxy-companion
    container_name: letsencrypt
    environment:
      - "[email protected]"
    restart: always
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    volumes_from:
      - https-proxy
    networks:
      - front

networks:
  front:
    external:
      name: https-proxy`

mailcow yaml (I have shown you only the parts you need to edit - compare it with your yaml file):

   nginx-mailcow:
      depends_on:
        - sogo-mailcow
        - php-fpm-mailcow
        - redis-mailcow
      image: nginx:mainline-alpine
      dns:
        - ${IPV4_NETWORK:-172.22.1}.254
      command: /bin/sh -c "envsubst < /etc/nginx/conf.d/templates/listen_plain.template > /etc/nginx/conf.d/listen_plain.active &&
        envsubst < /etc/nginx/conf.d/templates/listen_ssl.template > /etc/nginx/conf.d/listen_ssl.active &&
        envsubst < /etc/nginx/conf.d/templates/server_name.template > /etc/nginx/conf.d/server_name.active &&
        envsubst < /etc/nginx/conf.d/templates/sogo.template > /etc/nginx/conf.d/sogo.active &&
        envsubst < /etc/nginx/conf.d/templates/sogo_eas.template > /etc/nginx/conf.d/sogo_eas.active &&
        . /etc/nginx/conf.d/templates/sogo.auth_request.template.sh > /etc/nginx/conf.d/sogo_proxy_auth.active &&
        . /etc/nginx/conf.d/templates/sites.template.sh > /etc/nginx/conf.d/sites.active &&
        nginx -qt &&
        until ping phpfpm -c1 > /dev/null; do sleep 1; done &&
        until ping sogo -c1 > /dev/null; do sleep 1; done &&
        until ping redis -c1 > /dev/null; do sleep 1; done &&
        until ping rspamd -c1 > /dev/null; do sleep 1; done &&
        exec nginx -g 'daemon off;'"
      environment:
        - HTTPS_PORT=${HTTPS_PORT:-443}
        - HTTP_PORT=${HTTP_PORT:-80}
        - MAILCOW_HOSTNAME=${MAILCOW_HOSTNAME}
        - IPV4_NETWORK=${IPV4_NETWORK:-172.22.1}
        - TZ=${TZ}
        - ALLOW_ADMIN_EMAIL_LOGIN=${ALLOW_ADMIN_EMAIL_LOGIN:-n}
        - VIRTUAL_HOST=mail.yourdomain.com
        - LETSENCRYPT_HOST=mail.yourdomain.com
      volumes:
        - ./data/web:/web:ro
        - ./data/conf/rspamd/dynmaps:/dynmaps:ro
        - ./data/assets/ssl/:/etc/ssl/mail/:ro
        - ./data/conf/nginx/:/etc/nginx/conf.d/:rw
        - ./data/conf/rspamd/meta_exporter:/meta_exporter:ro
        - sogo-web-vol-1:/usr/lib/GNUstep/SOGo/
      restart: always
      networks:
        mailcow-network:
          aliases:
            - nginx
        proxy:

networks:
  proxy:
    external:
      name: https-proxy
  mailcow-network:
    driver: bridge
    driver_opts:
      com.docker.network.bridge.name: br-mailcow
      com.docker.network.driver.mtu: 1450 
    enable_ipv6: false
    ipam:
      driver: default
      config:
        - subnet: ${IPV4_NETWORK:-172.22.1}.0/24
        - subnet: ${IPV6_NETWORK:-fd4d:6169:6c63:6f77::/64}

this is how it's in my configs. as you can see there is not that much hassle to get it working.

you also need to create a network (prior to running containers) in docker as I did (https-proxy). docker-compose won't create it for you. docker network create https-proxy
you can also add roundcube to mailcows yaml. if there is a need I will post my config in my repo

Yes thanks I fixed it ! With similar config

Op 20 mrt. 2020 om 09:53 heeft jaffinio notifications@github.com het volgende geschreven:



firtst of all, jwilder's nginx proxy yaml:

`version: '2'

services:
https-proxy:
image: jwilder/nginx-proxy
container_name: https-proxy
restart: always
ports:

  • "80:80"
  • "443:443"
    volumes:
  • /var/run/docker.sock:/tmp/docker.sock:ro
  • ${PWD}/vhost.d:/etc/nginx/vhost.d
  • ${PWD}/html:/usr/share/nginx/html
  • ${PWD}/certs:/etc/nginx/certs
  • ${PWD}/uploadsize.conf:/etc/nginx/conf.d/uploadsize.conf
    networks:
  • front

letsencrypt-nginx-proxy-companion:
image: jrcs/letsencrypt-nginx-proxy-companion
container_name: letsencrypt
environment:

networks:
front:
external:
name: https-proxy`

mailcow yaml (I have shown you only the parts you need to edit - compare it with your yaml file):

`
nginx-mailcow:
depends_on:

  • sogo-mailcow
  • php-fpm-mailcow
  • redis-mailcow
    image: nginx:mainline-alpine
    dns:
  • ${IPV4_NETWORK:-172.22.1}.254
    command: /bin/sh -c "envsubst < /etc/nginx/conf.d/templates/listen_plain.template > /etc/nginx/conf.d/listen_plain.active &&
    envsubst < /etc/nginx/conf.d/templates/listen_ssl.template > /etc/nginx/conf.d/listen_ssl.active &&
    envsubst < /etc/nginx/conf.d/templates/server_name.template > /etc/nginx/conf.d/server_name.active &&
    envsubst < /etc/nginx/conf.d/templates/sogo.template > /etc/nginx/conf.d/sogo.active &&
    envsubst < /etc/nginx/conf.d/templates/sogo_eas.template > /etc/nginx/conf.d/sogo_eas.active &&
    . /etc/nginx/conf.d/templates/sogo.auth_request.template.sh > /etc/nginx/conf.d/sogo_proxy_auth.active &&
    . /etc/nginx/conf.d/templates/sites.template.sh > /etc/nginx/conf.d/sites.active &&
    nginx -qt &&
    until ping phpfpm -c1 > /dev/null; do sleep 1; done &&
    until ping sogo -c1 > /dev/null; do sleep 1; done &&
    until ping redis -c1 > /dev/null; do sleep 1; done &&
    until ping rspamd -c1 > /dev/null; do sleep 1; done &&
    exec nginx -g 'daemon off;'"
    environment:
  • HTTPS_PORT=${HTTPS_PORT:-443}
  • HTTP_PORT=${HTTP_PORT:-80}
  • MAILCOW_HOSTNAME=${MAILCOW_HOSTNAME}
  • IPV4_NETWORK=${IPV4_NETWORK:-172.22.1}
  • TZ=${TZ}
  • ALLOW_ADMIN_EMAIL_LOGIN=${ALLOW_ADMIN_EMAIL_LOGIN:-n}
  • VIRTUAL_HOST=mail.yourdomain.com
  • LETSENCRYPT_HOST=mail.yourdomain.com
    volumes:
  • ./data/web:/web:ro
  • ./data/conf/rspamd/dynmaps:/dynmaps:ro
  • ./data/assets/ssl/:/etc/ssl/mail/:ro
  • ./data/conf/nginx/:/etc/nginx/conf.d/:rw
  • ./data/conf/rspamd/meta_exporter:/meta_exporter:ro
  • sogo-web-vol-1:/usr/lib/GNUstep/SOGo/

ports:

restart: always
networks:
mailcow-network:
aliases:
- nginx
proxy:

networks:
proxy:
external:
name: https-proxy
rcube-back:
mailcow-network:
driver: bridge
driver_opts:
com.docker.network.bridge.name: br-mailcow
com.docker.network.driver.mtu: 1450
enable_ipv6: false
ipam:
driver: default
config:

  • subnet: ${IPV4_NETWORK:-172.22.1}.0/24
  • subnet: ${IPV6_NETWORK:-fd4d:6169:6c63:6f77::/64}
    `
    this is how it's in my configs. as you can see there is not that much hassle to get it working.

you also need to create a network in docker as I did (https-proxy). docker-compose won't create it for you. you can also add roundcube to mailcows yaml. if there is a need I will post my config in my repo

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHubhttps://github.com/mailcow/mailcow-dockerized/issues/3254#issuecomment-601592916, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AM3SRPVSCC7ATM3HLUH7YQ3RIMVITANCNFSM4KDIO2VA.

Thank you Jaffino, you saved me a lot of headache. Buy you a beer any day :D

Was this page helpful?
0 / 5 - 0 ratings

Related issues

schoebelh picture schoebelh  Â·  3Comments

phipag picture phipag  Â·  3Comments

Adorfer picture Adorfer  Â·  3Comments

RogerSik picture RogerSik  Â·  3Comments

zkryakgul picture zkryakgul  Â·  3Comments