# Tenant SSL requests fail because ssl-redirect.conf overrides the tenant's port-80 block (add ACME exception / fix load order)

**Project:** Sites | **Board:** Planned | **Votes:** 1
**URL:** https://roadmap.ploi.io/projects/2-site-level-requests/items/1670-tenant-ssl-requests-fail-because-ssl-redirectconf-overrides-the-tenants-port-80-block-add-acme-exception-fix-load-order

---

### 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`**: a `listen 80` server block whose `server_name` includes the main domain **and all tenant hostnames**. It contains only `return 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 own `listen 80` server 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

1. Create a site, request a Let's Encrypt certificate, and enable the HTTPS redirect.
2. Add tenants whose hostnames sort after "ssl-redirect" (e.g. `tickets.example.com`).
3. Request a tenant certificate with HTTP validation.
4. 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:

```nginx
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.
