How should my apache vhost config look like for the best results with autoconfig/autodiscover?

Your question

Hello,
I have this apache2 vhost config.
it works, but i have the impression it is not using autoconfig etc.

how should an optimal vhost config look like?

<VirtualHost *:80>
ServerName mail.example.de
ServerAlias mail… mail…de … some more

Redirect permanent / https://mail…de/

<VirtualHost *:443>
ServerName mail…de
ServerAlias mail…

SSLEngine on

SSLCertificateFile /etc/letsencrypt/live/mail.....de/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mail.....de/privkey.pem

ProxyAddHeaders On
ProxyPreserveHost On
ProxyRequests Off

ProxyPass /jmap/session http://127.0.0.1:8080/jmap/session
ProxyPassReverse /jmap/session http://127.0.0.1:8080/jmap/session

ProxyPass /.well-known/jmap http://127.0.0.1:8080/jmap/session
ProxyPassReverse /.well-known/jmap http://127.0.0.1:8080/jmap/session


ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/

ErrorLog ${APACHE_LOG_DIR}/stalwart-error.log
CustomLog ${APACHE_LOG_DIR}/stalwart-access.log combined

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

Autoconfig and autodiscover rely on DNS more than on any special Apache proxy rules: Mozilla Autoconfig and Microsoft Autodiscover expect their own subdomains (autoconfig.example.de and autodiscover.example.de) that resolve to the same host as your mail server, while the newer PACC protocol is served from the bare domain itself at https://example.de/.well-known/user-agent-configuration.json (no subdomain).

For your vhost to actually satisfy those lookups:

  1. DNS: add CNAME records autoconfig.example.de and autodiscover.example.de pointing at mail.example.de.
  2. Apache: you need vhosts (or ServerAliases) that answer for autoconfig.example.de, autodiscover.example.de, and, for PACC, the bare example.de domain, all proxying to Stalwart the same way your mail.example.de vhost does. Your current config only has aliases under mail..., so requests to autoconfig.example.de etc. wouldn’t be routed to Apache/Stalwart at all unless you add matching ServerName/ServerAlias entries (or a separate vhost block) covering those hostnames, with the same ProxyPass / http://127.0.0.1:8080/ rule.
  3. Once the hostname resolves and reaches the same reverse proxy, you don’t need special path-specific ProxyPass rules for /jmap/session or /.well-known/jmap — your blanket ProxyPass / http://127.0.0.1:8080/ already forwards everything, including /.well-known/user-agent-configuration.json, /autodiscover/autodiscover.xml, and /mail/config-v1.1.xml, since Stalwart generates all of those automatically for any HTTPS request reaching port 443. No extra Stalwart-side configuration is required beyond the standard mail services being enabled.

So the main fix is DNS + vhost coverage for the autoconfig. and autodiscover. subdomains (and the bare domain for PACC), not the proxy rules themselves.

See Autoconfig and DNS records.

This is an automated reply from the Stalwart Help Bot. Other community members may follow up if this answer is incomplete or wrong.