What is nginx and why it is in front of almost everything
Published on 2026-09-12 by frfrand
A reverse proxy explained without beating around the bush: what it solves, why your app shouldn't talk to the Internet directly, and the three errors that cause 502, 504, and 413.

Short answer: nginx is a web server that is almost always used as a reverse proxy: it receives Internet connections on port 443, terminates HTTPS, chooses the application based on the domain, and forwards the request via localhost. This way your app is never exposed, and errors 502, 504, and 413 tell you which segment of the path the problem is in.
Your application runs on port 3000. People enter through https://tudominio.com, which is port 443. Who connects them?
A reverse proxy. Almost always, nginx.
The word "reverse" comes from the comparison with the traditional proxy: that one represents the client before the servers; this one represents the servers before the client. From the outside, nginx is your site. Your application has no idea that the Internet exists.
What it concretely solves
Terminates HTTPS. The certificate lives in nginx. Your application receives plain HTTP via localhost and does not need to know anything about TLS, nor about renewals, nor about protocol versions.
Allows multiple sites on one server. nginx looks at the domain name requested by the browser and decides which application to send the request to. Three domains, three applications, one server, and one IP.
Serves static files. Images, CSS, JavaScript: nginx delivers them directly from disk, much faster than your application and without consuming its processes.
Protect. Your app has no ports exposed to the Internet. And along the way you can add request limits, blocklists, compression, and security headers.
The minimum configuration, line by line
server { listen 443 ssl; server_name miapp.com; ssl_certificate /etc/letsencrypt/live/miapp.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/miapp.com/privkey.pem;
location / { proxy_pass http://127.0.0.1:3000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; } }
The two ssl_certificate lines indicate where the certificate is located. The three headers are not decorative, and forgetting them causes confusing problems:
- Without Host, your application thinks the domain is localhost, and the URLs it generates will be wrong.
- Without X-Real-IP, all your visitors appear in the logs with the server's own address.
- Without X-Forwarded-Proto, your framework thinks the connection is HTTP and can create infinite redirects when trying to force HTTPS.
The three errors you will see
502 Bad Gateway. nginx could not communicate with your application. Almost never is the problem in nginx: your app is not running, it crashed, or it is listening on another port. Check your app's log first; nginx's error.log confirms the address it tried to connect to.
504 Gateway Timeout. Your application responded, but took longer than nginx expects (60 seconds by default). If it is a legitimately slow operation, increase proxy_read_timeout. Otherwise, the problem is the query.
413 Request Entity Too Large. Someone tried to upload a file larger than client_max_body_size, which defaults to 1 MB. This is very confusing because the error arrives before your code even knows about it.
The rule that prevents outages
nginx -t && systemctl reload nginx
Always both, always in that order. nginx -t validates the configuration and tells you the file and line of the error. Without that, a forgotten semicolon can leave your site down.
And reload, not restart: reload applies the new configuration without cutting connections that are in progress.
Where it fits in ArduMaker
On an ArduMaker VPS there are two nginx instances. The host's nginx that hosts your VPS terminates HTTPS: when activating a domain, the platform issues the certificate there (if you request it) and sends traffic for that domain to the nginx inside your VPS, which receives it on port 443 but as plain HTTP, because TLS has already been resolved. That is why, inside the VPS, the example block goes with listen 443;, without ssl and without the certificate lines.
That inner block is what decides which app the domain goes to, and activating the domain does not write it: it is written by the deployment of a repository or by you. If it is missing, the request falls into the default nginx block of the VPS, which shows an ArduMaker notice page instead of your application. To write it or adjust it, there is the nginx editor in the panel, which saves a copy of the previous file, validates with nginx -t, and if validation fails, leaves everything as it was: it is the nginx -t from above, but without the possibility of forgetting it.
Nginx in front of an API: the most common case
An API can listen on 127.0.0.1:8000 while Nginx receives HTTPS requests on 443. The proxy decides which application to send them to using the domain and logs connection errors with the upstream process.
On an ArduMaker VPS you can configure this architecture to separate public access from internal ports. If a 502 appears, check that the API is active and listening where Nginx attempts to connect; if the certificate fails, review DNS and TLS configuration before touching the backend.
Related: What is localhost · HTTP Errors.
Frequently Asked Questions
What is a reverse proxy? An intermediary that represents your servers to clients: the browser talks to nginx, and nginx talks to your application.
What does a 502 Bad Gateway mean? That nginx could not communicate with your application: it is down, listening on another port, or the domain block points to a port where nothing is listening.
What does a 504 Gateway Timeout mean? That your application took longer than nginx expects (60 seconds by default, adjustable with proxy_read_timeout).
Is it better to use reload or restart? reload, after validating with nginx -t: it applies the new configuration without interrupting ongoing connections.