Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always receiving "Internal Server Error" with naive Traefik configuration #1618

Closed
TuringTux opened this issue Jan 18, 2025 · 1 comment
Closed

Comments

@TuringTux
Copy link

I need to run smtp4dev behind a Traefik reverse proxy. While smtp4dev works nicely on its own, when reverse-proxying the requests, I am met with an HTTP 500 (Internal Server Error).

You can use this Docker Compose file to reproduce:

services:
    proxy:
        image: traefik:latest
        ports:
            - "80:80"
        command:
            - --providers.docker
            - --entrypoints.web.address=:80
        volumes:
            - /var/run/docker.sock:/var/run/docker.sock
    smtp4dev:
        image: rnwood/smtp4dev
        ports:
            - "81:80"
        labels:
            - traefik.http.routers.smtp4dev.rule=Host(`localhost`)

After starting this with

docker compose up

try accessing the following URLs:

  • http://localhost:81 — This will work (directly accessing the webserver in smtp4dev, without a reverse proxy)
  • http://localhost:80This will not work (accessing the webserver via the Traefik reverse proxy)

To check that Traefik is set up correctly, try replacing rnwood/smtp4dev with httpd to run a basic Apache server, which will respond under http://localhost:80.

Does smtp4dev choke on some of the HTTP headers that Traefik sends? Sadly, I am not seeing much debug output in smtp4dev either, but I can of course test things when necessary.

Thanks in advance :)

@TuringTux TuringTux changed the title smtp4dev in Docker yields "Internal Server Error" when behind Traefik Always receiving "Internal Server Error" with naive Traefik configuration Jan 18, 2025
@TuringTux
Copy link
Author

✅ I figured it out. The problem is that Traefik tries to route the HTTP requests to port 25 (the SMTP server). This can be fixed by manually telling Traefik where to route the HTTP requests to, e.g., like this:

services:
    proxy:
        image: traefik:latest
        ports:
            - "80:80"
        command:
            - --providers.docker
            - --entrypoints.web.address=:80
        volumes:
            - /var/run/docker.sock:/var/run/docker.sock
    smtp4dev:
        image: rnwood/smtp4dev
        ports:
            - "81:80"
        labels:
            - traefik.http.routers.smtp4dev.rule=Host(`localhost`)
            - traefik.http.services.smtp4dev-service.loadbalancer.server.port=80

Adding the traefik.http.services.smtp4dev-service.loadbalancer.server.port=80 line as described above was necessary (see also https://doc.traefik.io/traefik/routing/providers/docker/#routing-configuration for more details).

So, everything with smtp4dev works as expected. Sorry for bothering you, have a nice weekend!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant