Search code examples
docker-composenginx-reverse-proxyjwilder-nginx-proxyiredmailletsencrypt-nginx-proxy-companion

Cant setup iredmail behind existing jwilder-nginx-proxy ERR_TOO_MANY_REDIRECTS 301 Moved Permanently


This is my first time to setup iredmail. Am very happy to find this Group and really hope I will get some useful answers.

Has someone here ever succeed to setup iredmail/mariadb:stable behind an existing nginx jwilder/docker-gen reverse proxy already running multiples webapp and manages letsencrypt certificates?

I cant get my setup to work properly. I have to deal with ERR_TOO_MANY_REDIRECTS 301 Moved Permanently when I try to connect to my mail.domain.com I have already spent lot of time on this without a solution. Any idea to fix this?

iredmail-docker.conf conf file

HOSTNAME=webmail.domain.com
FIRST_MAIL_DOMAIN=domain.com
FIRST_MAIL_DOMAIN_ADMIN_PASSWORD=myp@ssw0rd
MLMMJADMIN_API_TOKEN=$(openssl rand -base64 32)
ROUNDCUBE_DES_KEY=$(openssl rand -base64 24)

docker-compose.yml conf file

version: '3.9'
services:
  iredmail:
    container_name: iredmail
    image: iredmail/mariadb:stable
    hostname: webmail.domain.com
    environment:
      # NGINX-PROXY ENVIRONMENT VARIABLES: UPDATE ME
      - VIRTUAL_HOST=webmail.domain.com
      - VIRTUAL_PORT=80
      - LETSENCRYPT_HOST=webmail.domain.com
      - [email protected]
      # END NGINX-PROXY ENVIRONMENT VARIABLES
      
    ports:
      # change the host ports to any available ports on your system, for example 8080 and 8443
      - "10080:80"
      - "10443:443"
      # keep the other ports unchanged
      - "110:110"
      - "995:995"
      - "143:143"
      - "993:993"
      - "25:25"
      - "465:465"
      - "587:587"
    volumes:
      - ./data/backup-mysql:/var/vmail/backup/mysql
      - ./data/mailboxes:/var/vmail/vmail1
      - ./data/mlmmj:/var/vmail/mlmmj
      - ./data/mlmmj-archive:/var/vmail/mlmmj-archive
      - ./data/imapsieve_copy:/var/vmail/imapsieve_copy
      - ./data/custom:/opt/iredmail/custom
      - ./data/ssl:/opt/iredmail/ssl
      - ./data/mysql:/var/lib/mysql
      - ./data/clamav:/var/lib/clamav
      - ./data/sa_rules:/var/lib/spamassassin
      - ./data/postfix_queue:/var/spool/postfix

    env_file:
      - iredmail-docker.conf
    networks:
    ....

Solution

  • I have finally found a working just solution after posting this question.

    So I have a new container that will handle SSL for webmail.domain.com which will then proxy all requests to the the iredmail container on port 443. Find new conf files below.

    Please make sure to update the network directive of your conf files to match your docker setup.

    1. iredmail docker-compose.yml conf file
    version: '3.9'
    services:
      iredmail:
        container_name: iredmail
        image: iredmail/mariadb:stable
        hostname: webmail.domain.com
          
        ports:
          # change the host ports to any available ports on your system, for example 8080 and 8443
          - "10080:80"
          - "10443:443"
          # keep the other ports unchanged
          - "110:110"
          - "995:995"
          - "143:143"
          - "993:993"
          - "25:25"
          - "465:465"
          - "587:587"
        volumes:
          - ./data/backup-mysql:/var/vmail/backup/mysql
          - ./data/mailboxes:/var/vmail/vmail1
          - ./data/mlmmj:/var/vmail/mlmmj
          - ./data/mlmmj-archive:/var/vmail/mlmmj-archive
          - ./data/imapsieve_copy:/var/vmail/imapsieve_copy
          - ./data/custom:/opt/iredmail/custom
          - ./data/ssl:/opt/iredmail/ssl
          - ./data/mysql:/var/lib/mysql
          - ./data/clamav:/var/lib/clamav
          - ./data/sa_rules:/var/lib/spamassassin
          - ./data/postfix_queue:/var/spool/postfix
     
        env_file:
          - iredmail-docker.conf
        networks:
        ...
    
    1. webmail.domain.com docker-compose.yml conf file
    version: '3.9'
    
    services: 
      webmail:
        container_name: webmail
        image: nginx:stable-alpine3.17
        networks:
          ...
        restart: always
        environment:
          # NGINX-PROXY ENVIRONMENT VARIABLES: UPDATE ME
          - VIRTUAL_HOST=webmail.domain.com
          - VIRTUAL_PORT=80
          - LETSENCRYPT_HOST=webmail.domain.com
          - [email protected]
          # END NGINX-PROXY ENVIRONMENT VARIABLES
        expose:
          - 80
        volumes:
          - ./logs/nginx:/var/log/nginx/
          - ./default.conf:/etc/nginx/conf.d/default.conf
          
    networks:
       ...
    

    Thats all! Run sudo docker compose up -d for each of your docker-compose.yml file and enjoy!!