Admin page redirect to hostname

Issue Description

When i first setup, i have set server hostname as mail.domain.com, i point A record to my server and MX too, i changed listenter to listen https on port 8443. Email function work perfectly. When i access https://mail.domain.com:8443/admin (i use cloudflare), i can access it, but when i fill username and press continue, it redirect me to container hostname instead of mail.domain.com, when i set hostname: mail.domain.com in docker compose, it redirect to the right domain. Here’s the compose

services:
    stalwart:
        image: stalwartlabs/stalwart:latest-alpine
        hostname: mail.artemisx.net
        restart: unless-stopped
        environment:
            STALWART_HTTPS_PORT: 8443
        ports:
            - "8443:8443"
            - "8080:8080"
            - "25:25"
            # - "587:587"
            - "465:465"
            # - "143:143"
            - "993:993"
            # - "110:110"
            # - "995:995"
            # - "4190:4190"
        volumes:
            - stalwart-etc:/etc/stalwart
            - stalwart-data:/var/lib/stalwart
    valkey:
        image: valkey/valkey:alpine
        restart: unless-stopped

volumes:
    stalwart-etc:
    stalwart-data:

Expected Behavior

Redirect to first setup hostname (not the autofill container hostname)

Actual Behavior

Redirect to docker container hostname

Reproduction Steps

  1. First setup hostname to mail.domain.com
  2. Add 8443 to https listener
  3. Access https://mail.domain.com:8443/admin
  4. Fill out username and Continue
  5. Redirect to container hostname

Stalwart Version

v0.16.x

Installation Method

Docker

Database Backend

RocksDB

Blob Storage

RocksDB

Search Engine

Internal

Directory Backend

Internal

I have reviewed the documentation and FAQ and confirm that my issue is NOT addressed there.

on

I have searched this support forum (open and closed topics) and confirm this is not a duplicate.

on

I understand that topics in this category are triaged by a bot first but a human reply will follow up. If I’d prefer a human-only reply, I’ll add the no-ai tag to my topic.

on

The issue is that your HTTPS listener is on port 8443, but Stalwart’s OAuth/OIDC/JMAP discovery documents default to publishing https://<defaultHostname> on port 443. After you enter your username, the OAuth callback redirect is built from that default base URL, which is why it sends you somewhere unexpected.

The fix is to set the STALWART_PUBLIC_URL environment variable in your Compose file so Stalwart knows its real public-facing URL (including the non-standard port):

services:
    stalwart:
        image: stalwartlabs/stalwart:latest-alpine
        hostname: mail.artemisx.net
        restart: unless-stopped
        environment:
            STALWART_HTTPS_PORT: 8443
            STALWART_PUBLIC_URL: https://mail.artemisx.net:8443
        ports:
            - "8443:8443"
            ...

When STALWART_PUBLIC_URL is set, it replaces the scheme, host, port, and optional path prefix in every published discovery URL. Note that STALWART_PUBLIC_URL does not affect Stalwart’s internal listener bindings - those continue to be configured separately. Setting the Docker hostname: is what you found as a workaround, but STALWART_PUBLIC_URL is the proper mechanism for this.

Reference: Environment variables - Public URLs

This is an automated reply from the Stalwart Help Bot. Other community members may follow up if this answer is incomplete or wrong. If you found it useful, mention @helpbot in any reply to ask follow-up questions and the bot will respond again.

Set STALWART_PUBLIC_URL as the bot suggested.