# Template: HTTPS for CrushMFT WebInterface

This template puts the CrushMFT WebInterface of several servers behind one HTTPS address. It makes one `https` listener that ends TLS at the balancer, keeps each user on the server that holds their session (the `CrushAuth` cookie), and tells CrushMFT the client's real address with a PROXY header.

Listeners › Add listener › **HTTPS for CrushMFT WebInterface**:

![The HTTPS for CrushMFT WebInterface template](Template-HTTPS-WebInterface/template.png)

| Field | What to enter |
|---|---|
| **Name** | a name for the listener |
| **Public port** | the port clients use, 443 |
| **Bind IP** | `0.0.0.0` for every interface |
| **Backends** | one CrushMFT web port per line, as `host` or `host:port` (8080 when a line has no port) |
| **CrushMFT ports expect a PROXY header** | on: CrushMFT then sees each client's address. Turn `proxy_header` on for those CrushMFT ports. |
| **CrushMFT ports use HTTPS (re-encrypt)** | on when the network between the balancer and CrushMFT is not trusted; type each CrushMFT HTTPS port |
| **Health-check user** and password | optional: a CrushMFT user with the SERVER_VIEW admin role. With it the health check logs in and reads the server's load. |

**Continue** shows the listener it made in the [listener editor](Listener-Editor.md), not saved yet. Change what you like, then **Save**.

## The details

**Balancer side** (what the template sets, or what you set):
- Mode `https`, public port 443 by default. TLS uses a generated, self-signed certificate until you set a keystore on the listener's TLS tab (`tls_keystore`, JKS, PKCS12 or JCEKS; one password for the keystore and its key).
- `sticky=cookie` with the cookie `CrushAuth` (`sticky_cookies`).
- `sticky_ttl` (default 1800 s) at least as long as CrushMFT's web session idle time; otherwise users who pause for longer are routed by client address or by the algorithm.
- PROXY v1 on each endpoint (the template's "CrushMFT ports expect a PROXY header" option, checked by default).
- One endpoint per CrushMFT server, port 8080 by default (one `host[:port]` per line).
- Optional health-check user: with a user (and its password) the template sets `probe=crushftp` with `probe_url=http://<host>:<port>/`, so health checks log in and read CrushMFT's metrics. The CrushMFT user needs the **SERVER_VIEW** (or SERVER_EDIT) admin role, and the backend must be Enterprise-licensed. Without a user the endpoints use the default `tcp` check (a connect).

**CrushMFT side**, on every backend:
- One **plain HTTP item** per backend that the balancer connects to, with **`proxy_header`** (PROXY v1) on.
- **`https_redirect` off** on the items behind the balancer (otherwise the browser loops), and **HTTP/3 off** on them.
- Port 80 to 443 redirects: point a separate `http` (or `tcp`) listener on port 80 at a **separate** CrushMFT HTTP item that has `https_redirect` on.
- Recommended: **CrushMFT Enterprise session replication** (`http_token_replication_lookup_allowed`), so users keep their session when a backend goes DOWN. Pins already survive balancer restarts (`sticky-pins.dat`, [Operating](Operating.md)).
- Use the same PROXY setting on every endpoint of the listener: CrushMFT binds a web session to the client address it sees, so mixing endpoints with and without PROXY breaks sessions after a switch.
- The balancer adds `X-Forwarded-For`, `-Proto`, `-Host`, `-Port` and `X-Real-IP` and removes those a client sent (unless the client is in `trusted_proxies`). It adds `; Secure` to `Set-Cookie` on `https` listeners. With PROXY on, CrushMFT's `allow_x_forwarded_host` is not needed.

**Optional re-encryption to CrushMFT (`backend_tls`).** For networks between the balancer and CrushMFT that you do not trust. The template option **"CrushMFT ports use HTTPS (re-encrypt)"** sets `backend_tls=true` on the generated endpoints and, with a health-check user, an `https://<host>:<port>/` probe URL on each endpoint's own host and port. The backend port still defaults to 8080, so type each CrushMFT HTTPS port.
- In CrushMFT use **one HTTPS item per backend** instead of the plain HTTP item, still with `proxy_header`: the PROXY header goes before the TLS handshake, which is what CrushMFT expects. Keep SNI off on those items.
- The CrushMFT certificate must be trusted in one of two ways:
  - **a certificate the Java trust store accepts for the endpoint's host name** (a CA-issued certificate for the name in `host`); or
  - **a pin.** For CrushMFT's self-signed certificate: save the listener, open each endpoint, click **Check certificate**, compare the SHA-256 fingerprint with the certificate on the CrushMFT server, then **Trust this certificate** and save. This stores the fingerprint in `backend_tls_pin`; the chain, dates and host name are then not checked.
- Until a certificate is trusted, the endpoint's health check is DOWN with "certificate not trusted (SHA-256 …)", and connections to it fail over.
- **When CrushMFT's certificate changes**, a pinned endpoint fails the same way: run Check certificate and Trust this certificate again. Until then the endpoint is DOWN.
- **The cost:** a second TLS session per connection (more CPU and memory per session, and one backend handshake per new back connection, resumed after the first).
- `backend_tls` applies only on `tls`, `http` and `https` listeners. A `tcp` listener relays the client's bytes unchanged, so the client's TLS already reaches CrushMFT end to end.
