Traffic
Static files and redirects
Not everything needs a backend. A holding page, a folder of downloads, or a domain you bought years ago and want to keep working are all one site with no application behind them at all.
Static mode
Set a site or a path to static, give it a folder on the load balancer, and nginx serves what is in it. This is the fastest thing nginx does and it costs almost nothing.
- A holding page while an application is being built or moved.
- Downloads that would otherwise flow through your application for no reason.
- A status page that keeps working when everything else is down, which is the whole point of putting it here rather than on the backend.
- The well known folder for things like security.txt.
Files have to be on every node, because either node can serve. Keep them in a folder you deploy to both, or accept that a page only present on one node will vanish at the next failover.
Redirect mode
Sends visitors somewhere else. There are two kinds and the difference matters.
| Kind | Status | What it means |
|---|---|---|
| Permanent | 301 | Browsers and search engines remember it and stop asking. Use this for a move that is really final. |
| Temporary | 302 | Nobody remembers it. Use this while you are still deciding. |
A permanent redirect is hard to take back
Browsers cache 301s aggressively and some of them for a very long time. If there is any chance you will change your mind, use a temporary one first and promote it later.
Redirects and certificate renewal
A redirect site still needs to answer on port 80 for the challenge path, or its certificate will not renew. The generated config handles this for you: the ACME path is excluded from the redirect. This is the single most common way a hand written redirect breaks renewal months later.
Common questions
Can I redirect one path and proxy the rest?
Yes. Set the site to proxy and give the path its own redirect mode.
Does a static site need a certificate?
Only if you want https, which you do. A static site gets a certificate the same way any other site does.
Where should the files live?
Anywhere on the node that the nginx user can read. Keep them out of paths the manager writes to, since those are rewritten on every apply.
Step by step instructions
The how to section has searchable, task shaped answers. Search it for redirect.