How to use it
- Enter the domain and choose static files or a reverse proxy.
- For static files set the document root. For a proxy enter the address of your app.
- Choose HTTPS, gzip and caching.
- Copy the result, save it in your nginx configuration, run
nginx -tand reload.
What you get
- A
serverblock withserver_namefor the domain, and optionally its www form. - With HTTPS: a second block on port 80 that redirects to
https://$host$request_uri, and a TLS block withssl_certificatepaths and TLS 1.2 and 1.3. - Gzip for text-based types, with
gzip_vary on. - For static sites:
try_files, optionally falling back to/index.html, andexpires 30dfor common asset types. - For a proxy:
proxy_passwithHost,X-Real-IP,X-Forwarded-ForandX-Forwarded-Protoheaders.
Example
Domain example.com, reverse proxy to http://127.0.0.1:3000 with HTTPS gives a redirect block and a TLS block whose location / passes requests to port 3000.
Tips
- Caching for 30 days works best with file names that change when content changes, such as app.3f2a.js.
- On nginx 1.25.1 and newer you can add
http2 on;to the TLS block.