Skip to content

Nginx Reverse Proxy & Load Balancer Config Generator

Pure frontend: pick a mode, enter a domain and backends, and get server / upstream blocks. Text is assembled locally — nothing is uploaded, validated remotely or written to your server.

How to use

Choose single-backend reverse proxy or multi-backend load balancing, then fill in the public domain, listen port and backend address. For multiple backends, enter two or three address:port lines and pick an algorithm. Generate config produces a copyable block, with notes on the parts most worth double-checking.

Decide on location matching before generating

Nginx proxy failures often get blamed on a dead backend when the request never reached the backend you had in mind. Location matching has a precedence: exact = first, then prefix ^~, then regex ~ / ~*, and plain prefixes last. If a broad location / proxies everything and you later add a regex for static files, the wrong modifier or ordering will be intercepted.

Think about the path prefix too. Exposing one domain makes root / proxying the simplest option. Several systems behind one domain need distinct prefixes such as /api/ and /admin/. The prefix goes on the location; the URI the backend receives depends on whether proxy_pass carries a URI — exactly what the strip-prefix toggle controls.

The trailing slash decides what the backend sees

This is the most common trap and deserves a full explanation. With location /api/ and a request for /api/user:

proxy_pass Path the backend receives Meaning
http://127.0.0.1:3000 /api/user No URI part, passed through
http://127.0.0.1:3000/ /user URI part, location prefix replaced
http://127.0.0.1:3000/backend/ /backend/user URI part, prefix replaced with given path

An application registering /users but receiving /api/users is missing a slash here. Conversely, if the backend has its own base path and expects /api, do not add one. The generator turns this choice into an explicit switch so you are not counting slashes by eye.

One limitation: when location uses a regex, proxy_pass cannot carry a URI part at all — Nginx rejects the config. That is why the generator does not add a slash for non-prefix paths.

Forwarded headers decide who the backend thinks you are

By default, proxying drops the client's original details. The four proxy_set_header lines each have a job: Host carries the original domain, X-Real-IP a single client address, X-Forwarded-For a chain whose first entry is usually the real client, and X-Forwarded-Proto records whether the client used http or https to reach Nginx.

Skip them and backend logs fill with 127.0.0.1, IP-based rate limiting lumps every user together, and a backend seeing $scheme as http after TLS termination can enter a redirect loop. Note that backend frameworks usually need their own "trust proxy" setting before they read these headers. The generator writes all four by default; trim them only with a reason.

upstream: a fancier algorithm is not automatically better

With several backends, the upstream block belongs in the http context, before the server block. Default round robin is enough for stateless services of similar capacity. least_conn hands each request to the backend with the fewest active connections, useful when request cost varies widely. ip_hash gives session affinity for legacy systems that cannot externalise sessions, though scaling nodes redistributes the mapping.

The generator does not write health checks for you. In production, use max_fails with fail_timeout or rely on the upstream's own health checking and service discovery. Leaving a dead node in the rotation means requests still reach it; no algorithm can compensate for that.

The fixed pre-deploy sequence

Put the generated block into a site config, run nginx -t for syntax validation, then reload gracefully with systemctl reload nginx. Do not skip it: a wrong path, a directive in the wrong context or a missing certificate file will break the live config on reload. Right after reloading, check the error and access logs to confirm backends are actually receiving requests.

Official documentation