# The reverse proxy

A web listener of CrushMFT can pass some of its requests on to **other** web servers. People reach one address and one certificate; behind it, requests for one host name or one path go to an application that is not open to the internet itself.

This page is about CrushMFT **as** the reverse proxy. For CrushMFT **behind** one, see [CrushMFT behind Apache, nginx or a load balancer](Ports-Behind-a-Proxy.md).

## Rules

The rules are on the **Advanced** tab of an [HTTP or HTTPS listener](Ports-HTTP.md), under **ReverseProxy Server Configuration**. **Add rule** adds a row; the bin at its end removes it.

| Field | What it is | Example |
|---|---|---|
| **Domain** | the host name the request came in for. `*` stands for any text; `!` in front turns the rule around: every name but this one. | `app.example.com` |
| **URL** | the web server to pass the request to | `http://10.0.1.50:8080/` |
| **Path** | the part of the site the rule is for. `/` is all of it. | `/` |

For each request the server goes through the rules from the top. The first rule whose **Domain** fits the host name and whose **Path** is the beginning of the requested path wins, and the request goes to its **URL**. A request that fits no rule is answered by CrushMFT itself.

## A whole host name

The simple and robust form: one host name per application.

| Domain | URL | Path |
|---|---|---|
| `wiki.example.com` | `http://10.0.1.50:8080/` | `/` |
| `tickets.example.com` | `http://10.0.1.51:3000/` | `/` |

Both names point at the CrushMFT server in DNS. `files.example.com`, which no rule names, is CrushMFT.

The certificate of the HTTPS listener must be good for all the names. With one certificate per name, turn on SNI: see [SSL on a port, SNI](Ports-SSL.md).

## A path of a host name

| Domain | URL | Path |
|---|---|---|
| `www.example.com` | `http://10.0.1.50:8080/` | `/wiki/` |

Requests for `https://www.example.com/wiki/…` go to the other server; everything else on that name stays with CrushMFT.

A path covers what is below it: `/wiki/` is `/wiki/page`, and not `/wikipedia`. The application behind must know that it lives under `/wiki/`: links in its pages that start at `/` would lead back to CrushMFT. Most applications have a setting for their "base URL"; where one has none, give it a host name of its own.

## What the other server sees

- The request, with its path and its headers, and an `X-Forwarded-For` header that names the client's address.
- A connection that comes from CrushMFT's address.

To a destination that speaks HTTPS, the server checks the certificate like any client.

## What CrushMFT adds

- One open port and one certificate for several applications.
- The server's rules against hammering: an address that is banned by CrushMFT does not reach the applications either. See [Banning](Prefs-Banning.md).
- The listener's [IP restrictions](Ports-IP-Restrictions.md).
- Protection against requests that try to climb out of the proxied path with tricks in the address. Such requests are refused.

It does not add a login: whoever can reach the listener can reach the application. The application keeps its own.

## Things to know

- The reverse proxy passes HTTP on. For anything else, use [port forwarding](Ports-Port-Forward.md).
- Applications that use WebSockets, very long requests or streaming should be tried before people depend on them.
- Rules by address of the **user** rather than by host name, for sending some users to another server altogether, are the [proxy rules](Prefs-WebInterface-Proxy-Rules.md) of the Preferences.
