Tenant SSL requests fail because ssl-redirect.conf overrides the tenant's port-80 block
When a site already has SSL and a redirect, and you add tenants to it, Let's Encrypt requests for some of those tenants fail. "Force request (skip DNS verification)" doesn't help. This happens to us regularly.
What's going on
For a site app.example.dev with tenants, Ploi puts these files in /etc/nginx/ploi/app.example.dev/before/:
ssl-redirect.conf: alisten 80server block whoseserver_nameincludes the main domain and all tenant hostnames. It contains onlyreturn 301 https://$host$request_uri;and has no exception for/.well-known/acme-challenge/.- One file per tenant (e.g.
tickets.example.com), each with its ownlisten 80server block that serves/.well-known/from the site webroot.
So every tenant hostname is defined twice on port 80. nginx logs:
nginx: [warn] conflicting server name "tickets.example.com" on 0.0.0.0:80, ignored
nginx uses whichever block loads first. Includes load alphabetically, so the result depends on the tenant's name:
| Tenant | Loads | Wins on port 80 | Certificate request |
|---|---|---|---|
business.example.com |
before ssl-redirect.conf |
tenant block | ✅ works |
tickets.example.com |
after ssl-redirect.conf |
redirect | ❌ fails |
voucher.example.com |
after ssl-redirect.conf |
redirect | ❌ fails |
For the failing tenants, the HTTP-01 challenge gets a 301 to HTTPS, and there's no certificate for that tenant on 443 yet, so validation fails. Behind Cloudflare it shows up as a 525. From the user's side it looks random: some tenants get a certificate and others don't, with identical settings.
Steps to reproduce
- Create a site, request a Let's Encrypt certificate, and enable the HTTPS redirect.
- Add tenants whose hostnames sort after "ssl-redirect" (e.g.
tickets.example.com). - Request a tenant certificate with HTTP validation.
- The challenge URL returns a 301 to HTTPS and the request fails.
Expected behaviour
A tenant certificate request should work for every tenant, whatever its name.
Proposed fixes
Any one of these would solve it:
1. Add an ACME exception to the generated ssl-redirect.conf, so it matches the main site config:
server {
listen 80;
listen [::]:80;
server_name .app.example.dev tickets.example.com voucher.example.com;
location ^~ /.well-known/acme-challenge/ {
root /home/<user>/<site>/public;
try_files $uri =404;
}
location / {
return 301 https://$host$request_uri;
}
}
2. Don't put tenant hostnames in ssl-redirect.conf. Generate the redirect inside each tenant's own config once that tenant has a certificate.
3. Make the load order deterministic, e.g. by renaming the file to zz-ssl-redirect.conf so tenant blocks always load first, and get rid of the duplicate server_name definitions.
Related
The generated tenant config uses the PHP template (try_files … /index.php, fastcgi_pass), even when the main site is a Node app using proxy_pass. Once a tenant has a certificate, it may serve the PHP webroot over HTTPS instead of the app. It would help if tenant configs followed the main site's type.
Tenant SSL requests fail because ssl-redirect.conf overrides the tenant's port-80 block (add ACME exception / fix load order)
-
Dennis moved item to board Planned
47 minutes ago -
Kay van Aarssen moved item to project Sites
3 hours ago -
Kay van Aarssen created the item
3 hours ago