Fill in these first
- Domain: [e.g. example.com]
- Redirect www to the bare domain, or the other way: [choose one]
- App address: [e.g. 127.0.0.1:3000]
- Certificate paths: [e.g. issued by a free certificate tool, paths if known]
- Static folder served by Nginx directly, if any: [e.g. /var/www/app/public at /assets/]
- Largest upload the app accepts: [e.g. 10 MB]
- WebSockets used: [yes or no]
- Behind a CDN or load balancer: [yes, name the type, or no]
Task
Write the Nginx configuration for this app and explain it.
Output format
- One complete config file in a code block, with a short comment above each block.
- It must include: an HTTP to HTTPS redirect, the www redirect chosen, TLS 1.2 and 1.3 only, proxy headers for host, real IP and protocol, timeouts, the upload limit, gzip for text types, and WebSocket upgrade headers only if WebSockets are used.
- Security headers: Strict-Transport-Security, X-Content-Type-Options, Referrer-Policy, a frame rule, and a starter Content-Security-Policy marked as needing review.
- | Header | What it prevents | Safe starting value |
- Commands to test and reload: nginx -t, then a reload, never a restart first.
- A five-point check after reload: redirects, certificate, headers, uploads, app logs showing the real client IP.
Rules
- If behind a CDN, read the client IP only from that CDN's header and trusted ranges, and say so.
- Do not hide the app port with security through obscurity; bind the app to localhost.
- Mark anything that depends on the app, such as the Content-Security-Policy, as needing a check.






