[GH-ISSUE #483] Nginx configuration #314

Closed
opened 2026-03-15 13:50:25 +03:00 by kerem · 3 comments
Owner

Originally created by @donakhseputa on GitHub (Apr 28, 2025).
Original GitHub issue: https://github.com/axllent/mailpit/issues/483

Nginx conf

server {
    listen 80;

    # Redirect all HTTP requests to HTTPS
    location / {
        return 301 https://$host$request_uri;
    }
}

server {
    listen 443 ssl;

    ssl_protocols TLSv1.2 TLSv1.3;

    ### Localhost SSL
    ssl_certificate /etc/letsencrypt/live/${SERVER_DOMAIN}/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/${SERVER_DOMAIN}/privkey.pem;

    # ssl_ciphers HIGH:!aNULL:!MD5;
    # include /etc/letsencrypt/options-ssl-nginx.conf;
    # ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    root /var/www/public;
    index index.php index.html;

    # Log location
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    # Set client body size
    client_max_body_size 8M;

    # Mailpit block location
    location /mailbox/ {
        proxy_pass https://mailpit:8025;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_cache_bypass $http_upgrade;
        rewrite ^/mailbox/(.*)$ /$1 break;
    }

    # Laravel block location
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass laravel:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
    }

    location ~ /\.ht {
        deny all;
    }
}

Docker-compose

services:
    mailpit:
        image: axllent/mailpit:latest
        restart: unless-stopped
        tty: true
        ports:
            - ${DC_MAILPIT_PORT}:1025
            - ${DC_MAILPIT_INBOX_PORT}:8025

when access to https://mydomain.com/mailbox, its show blank page
asset https://mydomain.com/dist/app.css instead https://mydomain.com/mailbox/dist/app.css

When I try add environment "MP_WEBROOT: /mailbox/" and restart nginx, page show "page not found"
I try open asset, and URL become https://mydomain.com/mailbox/mailbox/dist/app.css

Originally created by @donakhseputa on GitHub (Apr 28, 2025). Original GitHub issue: https://github.com/axllent/mailpit/issues/483 Nginx conf ``` server { listen 80; # Redirect all HTTP requests to HTTPS location / { return 301 https://$host$request_uri; } } server { listen 443 ssl; ssl_protocols TLSv1.2 TLSv1.3; ### Localhost SSL ssl_certificate /etc/letsencrypt/live/${SERVER_DOMAIN}/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/${SERVER_DOMAIN}/privkey.pem; # ssl_ciphers HIGH:!aNULL:!MD5; # include /etc/letsencrypt/options-ssl-nginx.conf; # ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; root /var/www/public; index index.php index.html; # Log location access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; # Set client body size client_max_body_size 8M; # Mailpit block location location /mailbox/ { proxy_pass https://mailpit:8025; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_cache_bypass $http_upgrade; rewrite ^/mailbox/(.*)$ /$1 break; } # Laravel block location location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { include fastcgi_params; fastcgi_pass laravel:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; fastcgi_param DOCUMENT_ROOT $realpath_root; } location ~ /\.ht { deny all; } } ``` Docker-compose ``` services: mailpit: image: axllent/mailpit:latest restart: unless-stopped tty: true ports: - ${DC_MAILPIT_PORT}:1025 - ${DC_MAILPIT_INBOX_PORT}:8025 ``` when access to https://mydomain.com/mailbox, its show blank page asset `https://mydomain.com/dist/app.css` instead `https://mydomain.com/mailbox/dist/app.css` When I try add environment "MP_WEBROOT: /mailbox/" and restart nginx, page show "page not found" I try open asset, and URL become `https://mydomain.com/mailbox/mailbox/dist/app.css`
kerem 2026-03-15 13:50:25 +03:00
  • closed this issue
  • added the
    stale
    label
Author
Owner

@axllent commented on GitHub (Apr 28, 2025):

I think you're trying to mix two things here. Note the following is untested, but I'm fairly confident it should work: You want https://${SERVER_DOMAIN}/mailbox/ to return Mailpit, so rather than rewriting anything, set proxy_pass https://mailpit:8025/mailbox/; and remove the rewrite rule, and finally tell Mailpit that you are using the /mailbox/ webroot by setting the MP_WEBROOT: /mailbox/.

<!-- gh-comment-id:2834660193 --> @axllent commented on GitHub (Apr 28, 2025): I think you're trying to mix two things here. Note the following is untested, but I'm fairly confident it should work: You want `https://${SERVER_DOMAIN}/mailbox/` to return Mailpit, so rather than rewriting anything, set `proxy_pass https://mailpit:8025/mailbox/;` and **remove** the `rewrite` rule, and finally tell Mailpit that you are using the `/mailbox/` webroot by setting the `MP_WEBROOT: /mailbox/`.
Author
Owner

@github-actions[bot] commented on GitHub (May 6, 2025):

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

<!-- gh-comment-id:2853067041 --> @github-actions[bot] commented on GitHub (May 6, 2025): This issue has been marked as stale because it has been open for 7 days with no activity.
Author
Owner

@github-actions[bot] commented on GitHub (May 9, 2025):

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

<!-- gh-comment-id:2864885204 --> @github-actions[bot] commented on GitHub (May 9, 2025): This issue was closed because there has been no activity since being marked as stale.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/mailpit#314
No description provided.