Contents
Nginx was built to solve one specific problem: serving a very large number of concurrent connections without running the server out of memory. That’s why it’s now so common at the front of websites and apps, either on its own or in front of other servers.
How Nginx works
- A master process and worker processes: each worker handles thousands of connections through an event loop instead of one process per connection.
- No .htaccess: all configuration lives in central files such as
nginx.confandserverblocks, and you reload the config after each change. - No built-in PHP: PHP requests are handed to PHP-FPM over FastCGI.
- Sometimes paired with Apache: in some setups Nginx sits in front of Apache, serving static files itself and passing dynamic requests through.
sudo nginx -t && sudo systemctl reload nginx
Example: reverse proxy for a Node.js app
server {
listen 80;
server_name app.example.com;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Nginx accepts visitors on port 80 and forwards requests to the app running internally on port 3000.
Common confusions and problems
- Apache rules don’t carry over: WordPress on Nginx uses
try_files $uri $uri/ /index.php?$args;instead of theRewriteRulelines in .htaccess. - Error 502: the app behind Nginx is down or on another port. See the 502 error explained.
- Error 413: the upload is larger than
client_max_body_size. - Nginx isn’t always faster: with good caching, modern web servers perform close to each other.
On ArabyHost
The web server on ArabyHost is LiteSpeed, not Nginx, and there’s no root access to install or configure Nginx. On the developer plans, Node.js and Python apps run through CloudLinux selectors with Phusion Passenger, so you don’t write any proxy_pass: you set the app folder and startup file and Passenger does the rest, as in the Node.js deployment guide. Redirect rules go in .htaccess. If your project needs a custom Nginx setup, you need a VPS, which ArabyHost doesn’t offer yet.
FAQ
Does .htaccess work with Nginx?
No. Nginx doesn't read .htaccess files at all; every rule lives in the server's own config files. Apache rules have to be converted to Nginx syntax by hand.
What is a reverse proxy?
A server that receives visitors' requests and passes them to an app running behind it on an internal port, such as a Node.js app on port 3000, then returns the response. It helps with SSL, caching and load balancing.
Why do I get 502 Bad Gateway with Nginx?
Nginx is running but didn't get a valid response from the app behind it. Usually the app is down or listening on a different port from the one in proxy_pass.