axllent / mailpit

An email and SMTP testing tool with API for developers
https://mailpit.axllent.org
MIT License
5.66k stars 139 forks source link

When accessing UI through nginx proxy, just get a white screen. #362

Closed penright closed 1 month ago

penright commented 1 month ago

I hope it is ok to ask a question here. I am guessing it has to be a configuration issue or I am misunderstanding the web UI.

Docker compose for mailpit

  mailpit:
    image: axllent/mailpit
    container_name: mailpit
    restart: unless-stopped
    volumes:
      - $PWD/storage/production_files/mailpit/data:/data
    #ports:
    #- 8025:8025
    #- 1025:1025
    environment:
      - MP_MAX_MESSAGES=5000
      - MP_DATABASE=/data/mailpit.db
      - MP_SMTP_AUTH_ACCEPT_ANY=1
      - MP_SMTP_AUTH_ALLOW_INSECURE=1
      - TZ=America/Chicago
    networks:
      - api-v3

The nginx

  nginx:
    container_name: nginx
    image: nginx:alpine
    environment:
      - TZ=America/Chicago
    depends_on:
      - php
    restart: unless-stopped
    ports:
      - ${NGINX_PORT:-443}:${NGINX_PORT:-443}
      - ${NGINX_PORT:-80}:${NGINX_PORT:-80}
    volumes:
      - $PWD/storage/web/etc/nginx/conf.d/:/etc/nginx/conf.d/
      - $PWD/storage/web/var/www/certbot/:/var/www/certbot/
      - $PWD/storage/web/var/www/app/:/var/www/app/
      - $PWD/storage/web/etc/letsencrypt/:/etc/letsencrypt/
    networks:
      - api-v3

The nginx config root is /var/www/app for the larvavel project. There was not one in the example, so I assumed that I needed to add one to the location.

    location /mailpit {
        auth_basic "Restricted";
        auth_basic_user_file /etc/nginx/conf.d/.htpasswd;

        proxy_pass http://mailpit:8025/;
        root /;

        # configure the websocket
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
    }

and here is what the nginx logs look like

/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf differs from the packaged version
/docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2024/09/13 11:57:55 [notice] 1#1: using the "epoll" event method
2024/09/13 11:57:55 [notice] 1#1: nginx/1.27.1
2024/09/13 11:57:55 [notice] 1#1: built by gcc 13.2.1 20240309 (Alpine 13.2.1_git20240309)
2024/09/13 11:57:55 [notice] 1#1: OS: Linux 6.8.0-44-generic
2024/09/13 11:57:55 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2024/09/13 11:57:55 [notice] 1#1: start worker processes
2024/09/13 11:57:55 [notice] 1#1: start worker process 29
2024/09/13 11:57:55 [notice] 1#1: start worker process 30
2024/09/13 11:57:55 [notice] 1#1: start worker process 31
2024/09/13 11:57:55 [notice] 1#1: start worker process 32
98.173.248.213 - bradmin [13/Sep/2024:11:58:14 -0500] "GET /mailpit HTTP/1.1" 200 474 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36"
98.173.248.213 - bradmin [13/Sep/2024:11:58:14 -0500] "GET /dist/app.css?v1.20.4 HTTP/1.1" 404 164 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36"
98.173.248.213 - bradmin [13/Sep/2024:11:58:14 -0500] "GET /dist/app.js?v1.20.4 HTTP/1.1" 404 163 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36"
axllent commented 1 month ago

Hi @penright, definitely the right place to ask. So you're proxying /mailpit to the Mailpit container, however you also need to tell Mailpit that. The Mailpit environment option you're looking for is MP_WEBROOT (see https://mailpit.axllent.org/docs/configuration/runtime-options/).

I don't know what the NginX root /; does, but I strongly suspect your don't need it.

Hope this helps!

penright commented 1 month ago

I tried many different combinations and that is what I last tried. :-) I saw we web root env var. It said the default was /. The example was /mail. image

So would I set the web root env var to /mail? If so in the docker-compose, do I need to persist that dir? Then the nginx root would be /mail?

if I docker exec -it into the mailpit container, where would I find the dir?

axllent commented 1 month ago

If you have proxied /mailpit to Mailpit, then your webroot in Mailpit would be mailpit. Does that not work?

axllent commented 1 month ago

Sorry, the second question you had is where you would find the dir. There is no dir, it's all coming from within the Mailpit binary itself. Mailpit has those files inside itself, so serves them back to the browser. This is why you need to tell Mailpit if you are using an alternative webroot.

github-actions[bot] commented 1 month ago

This issue has been marked as stale because it has been open for 7 days with no activity.

github-actions[bot] commented 1 month ago

This issue was closed because there has been no activity since being marked as stale.