Dev
Nginx Location Block Generator
An nginx config that works is usually a mix of copy-pasted blocks, some missing a header or using the wrong directive. This tool generates one correct location block for a specific task, ready to drop into an existing server block. Pick the task — Proxy to backend, Serve static files, API rate limit, Deny path, or WebSocket upgrade — and enter the URL path. The proxy block sets the four standard forwarding headers. The static files block uses `alias`, 30-day `expires`, and `Cache-Control: public, immutable`. The rate limit block shows the `http`-context `limit_req_zone` as a comment plus `limit_req burst=20 nodelay`. The WebSocket block sets `proxy_http_version 1.1` and both upgrade headers. The deny block returns 403. Paste inside your `server {}` context and run `nginx -t` before reloading.
How to use
- Choose your options above
- Click Generate
- Copy your result
Detailed instructions
- Pick the location task.
- Enter the URL path it should match.
- Click Generate to produce the location block.
- Paste it into your server block and run nginx -t.
Use Cases
- •Adding a proxy route to an existing nginx server block
- •Serving a static directory with caching headers
- •Applying a rate limit to an API path
- •Denying access to a sensitive path
- •Recalling the headers a WebSocket upgrade needs
Tips
- →Validate with nginx -t before every reload to catch typos.
- →Use alias for a directory mapping and root for a path prefix.
- →Set a long proxy_read_timeout for WebSocket connections.
- →Put the rate-limit zone in the http block, not the location.
FAQ
where does this block go in my nginx config
Paste it inside an existing `server {}` block. A `location` directive is only valid within a `server` or another `location` context — it sits alongside your other locations and inherits the server's `server_name` and TLS settings.
why does the WebSocket block need special headers
A WebSocket connection starts as an HTTP request asking to upgrade the protocol. Setting `proxy_http_version 1.1` and forwarding the `Upgrade` and `Connection: upgrade` headers tells nginx to pass that handshake through to the upstream instead of treating it as a regular request.
why is the rate limit zone shown as a comment outside the block
`limit_req_zone` must be defined in the `http {}` context, not inside a `location`. The generator shows it as a comment there because the location block references it by name with `limit_req zone=api`, and both halves must exist for rate limiting to work.
You might also like
Popular tools from other categories that share themes with this one.
Try these next
More free tools from other corners of the catalog, picked by shared themes.