NginxNginx A fast, popular program that sends web pages to visitors and can pass requests on to apps behind it. More about Nginx → (said “engine x”) is free, open-source software that runs on a server and answers requests from browsers. This guide is for anyone who has met the name on a hosting plan, in an error message or in a tutorial and wants to understand what it is, what it does and how to work with it.
Nginx is a web serverWeb server The program that answers visitors’ browsers and sends them your website. Also used for the computer it runs on. More about Web server → and reverse proxy: it receives every request a visitor’s browser sends, then either sends back a file itself (HTML, images, CSS) or passes the request to an application such as PHP-FPMPHP-FPM The part of the server that runs PHP code, the language WordPress and many sites are written in, and hands the finished page to the web server. More about PHP-FPM → or Node.js and returns the answer. It is known for handling many connections at once with little memory. You control it through text files in /etc/nginx/, and after every change you run sudo nginx -t and then sudo systemctl reload nginx.
What Nginx does
When someone visits https://example.com, their browser looks up the domain’s IP addressIP address The number address of a device on the internet, like 203.0.113.10. Computers use it to find each other, the way post uses street addresses. More about IP address → (say 203.0.113.10) and connects to that server on port 443. Something on the server has to accept that connection, read the request and send a reply. That something is the web server, and on a large share of the world’s servers it is Nginx.
Nginx does four main jobs. Most sites use two or three of them at once.
| Job | What it means | Example |
|---|---|---|
| Web server | Sends files from a folder straight to the browser | Serving /var/www/example.com/public/index.html |
| Reverse proxy | Passes requests to another program and returns its reply | Sending WordPress requests to PHP-FPM, or app requests to a Node.js app on port 3000 |
| HTTPS endpoint | Holds the SSL certificate and encrypts the connection | Using a Let’s Encrypt certificate for example.com |
| Load balancer | Shares traffic across several servers and skips failed ones | Two app servers behind one public address |
It can also cacheCache A saved copy of something, kept so it does not have to be made or fetched again. Like keeping a printed copy instead of reprinting it for every person who asks. More about Cache → replies, compress them with gzip, redirect old addresses to new ones and limit how fast one visitor can send requests.
Nginx does not run PHP, Python or JavaScript itself. For a WordPress site it hands PHP files to PHP-FPM, a separate service, and sends back the page PHP-FPM builds. This split is why a stopped PHP-FPM shows up as an Nginx error page.
How Nginx handles many visitors at once
Older web server designs often gave each connection its own process or thread. That is simple, but each one uses memory while it waits for a slow visitor on a mobile connection, so thousands of idle visitors can exhaust a server.
Nginx works differently. It starts one master process, which reads the configuration and manages the others, and a small number of worker processes, usually one per CPU core. Each worker is event-driven: rather than waiting on one connection, it keeps a list of thousands of open connections and deals with whichever one has something ready (new data arrived, a file finished reading, a reply can be sent). Nothing sits idle holding memory while a visitor is slow.
You can see this on any server running Nginx:
ps -o pid,user,cmd -C nginx
You should see one line that says nginx: master process (running as root, so it can open portsPort A numbered door on a server. Each service listens behind its own door: web pages on 443, email on others, remote login on 22. More about Port → 80 and 443) and one or more nginx: worker process lines running as an unprivileged user: www-data on Ubuntu and Debian, nginx on AlmaLinux and Rocky Linux.
Two settings near the top of the main configuration file control this:
worker_processes auto;
events {
worker_connections 768;
}
auto starts one worker per CPU core. worker_connections is how many connections each worker may hold open at once. The defaults are fine for most small and medium sites.
Nginx compared with Apache
Apache is the other long-established open-source web server, and it is the one cPanelcPanel The most popular hosting control panel: a website where you manage your email, files, databases and domains with point-and-click tools instead of commands. More about cPanel → servers use by default. Both are reliable and both can run WordPress well. The differences that matter in daily use:
| Nginx | Apache | |
|---|---|---|
| Design | Event-driven workers | Process or thread based modules (event MPM on modern setups) |
| Per-folder settings | Not supported: all settings live in the main configuration | .htaccess files in any folder |
| PHP | Always through PHP-FPM | PHP-FPM or a built-in module |
| Configuration changes | Need access to /etc/nginx and a reload | Many can be made in .htaccess with no reload |
| Common use | Front of the stack, static files, reverse proxy | Shared hosting, cPanel servers |
The biggest practical difference is .htaccess. Plugins and tutorials that say “add these lines to .htaccess” do nothing on Nginx. The equivalent rules have to be written as Nginx directives in the site’s configuration file, which needs root accessRoot access Full administrator control of a server: you can change anything, including things that break it. More about Root access →. Many servers run both: Nginx in front for HTTPS and static files, Apache behind it for sites that rely on .htaccess.
How Nginx configuration works
Everything Nginx does is decided by plain text files. You edit them, test them and reload.
Where the files are
| What | Ubuntu and Debian | AlmaLinux and Rocky Linux |
|---|---|---|
| Main file | /etc/nginx/nginx.conf | /etc/nginx/nginx.conf |
| Site files | /etc/nginx/sites-available/, linked into /etc/nginx/sites-enabled/ | /etc/nginx/conf.d/ (files ending in .conf) |
| Default web root | /var/www/html | /usr/share/nginx/html |
| Logs | /var/log/nginx/access.log and error.log | /var/log/nginx/access.log and error.log |
Directives, blocks and server blocks
The configuration is made of directives, each ending in a semicolon, grouped into blocks in curly brackets. The block you will edit most is the server block (ApacheApache One of the most common programs that sends web pages to visitors. It is the waiter between your website’s files and the people asking for them. More about Apache → calls the same idea a virtual host). One server block describes one site:
server {
listen 80;
server_name example.com www.example.com;
root /var/www/example.com/public;
index index.html index.php;
location / {
try_files $uri $uri/ =404;
}
}
Read it line by line:
listen 80;accepts plain HTTP connections on port 80.server_namelists the domain names this block answers for. Nginx compares it with the Host the browser asked for, which is how one server can host many sites on one IP address.rootis the folder files are served from.location /applies to every address on the site.try_fileslooks for a matching file, then a matching folder, and otherwise returns a 404.
Adding proxy_pass inside a location turns that part of the site into a reverse proxy, and adding fastcgi_pass hands PHP files to PHP-FPM. The Nginx install guide builds a complete working site from this block, including PHP.
The commands you will use
These work on Ubuntu 22.04 and 24.04, Debian 12, AlmaLinux 9 and Rocky Linux 9.
Install and start
On Ubuntu and Debian, Nginx starts by itself after installing:
sudo apt update
sudo apt install nginx
On AlmaLinux and Rocky Linux you start and enable it yourself:
sudo dnf install nginx
sudo systemctl enable --now nginx
Then allow web traffic through the firewall and visit http://203.0.113.10 (your server’s address). The Nginx welcome page means it works.
Check, test and reload
- Check it is running:
systemctl status nginxshould sayactive (running). - See which version you have:
nginx -v. - After any change, test the configuration:
sudo nginx -t. Only carry on if it reportssyntax is okandtest is successful. - Apply the change:
sudo systemctl reload nginx. A reload starts new workers with the new settings and lets the old ones finish their current requests, so visitors are not cut off. - To see the full configuration Nginx is actually using, with every included file joined together:
sudo nginx -T.
Use reload, not restart, for configuration changes. A restart stops Nginx completely first, and if the new configuration has a mistake, the site stays down. A failed reload leaves the old, working configuration running.
Read the logs
When something goes wrong, the error log usually says exactly what:
sudo tail -n 50 /var/log/nginx/error.log
The access log records every request with its status codeHTTP status code The three-digit number a website sends back with every page, saying how it went: 200 means fine, 404 means not found, 500 means the site itself broke. More about HTTP status code →, which is the quickest way to see whether visitors are getting 200, 404 or 502 replies:
sudo tail -f /var/log/nginx/access.log
Press Ctrl+C to stop following it.
Common problems
| Symptom | Cause | Fix |
|---|---|---|
| nginx -t reports an error with a file and line number | A missing semicolon or bracket, or a misspelt directive | Open that file at that line, correct it, test again before reloading |
| 502 Bad Gateway | Nginx is fine but the program behind it (PHP-FPM, Node.js) is stopped or crashed | Check the backend service and the error log. See how to fix 502 Bad Gateway |
| 504 Gateway Timeout | The backend is running but too slow to reply | Find the slow request first, then raise the timeout only if the work is genuinely long |
| Welcome page shows instead of your site | Your server block is not enabled, or server_name does not match the domain | Check the link in sites-enabled (Ubuntu) or the .conf file name (AlmaLinux), then check server_name |
| 403 Forbidden | No index file in the folder, or the worker user cannot read the files | Add index.html or index.php, and make the files readable by www-data or nginx |
| bind() to 0.0.0.0:80 failed (Address already in use) | Another program, often Apache, already uses port 80 | Run sudo ss -tlnp to find it, then stop it or move one of them to another port |
| .htaccess rules have no effect | Nginx ignores .htaccess files | Rewrite the rules as Nginx directives in the server block |
Where to go next
If you are setting up a server yourself, work in this order: install Nginx and add your first site, open the firewallFirewall A gatekeeper that decides which connections are allowed into a server and blocks the rest. More about Firewall →, then get a free SSL certificate with Let’s Encrypt so the site loads over HTTPSHTTPS The secure version of the web, shown by the padlock. Everything sent between you and the site is scrambled so nobody in between can read or change it. More about HTTPS →. If you run apps on their own ports, the reverse proxy guide shows how to put Nginx in front of them.
If you are on shared or cPanel hosting, you will rarely edit Nginx yourself. It is still worth knowing what it is, because its name appears on error pages and its behaviour explains why some .htaccess tricks work on one host and not another.
Official documentation
- Nginx documentation: the full reference for every directive and module.
- Nginx beginner’s guide: starting, stopping and the structure of the configuration file.
Related
- How to install Nginx on Ubuntu: set up Nginx and serve your first site, step by step.
- What is a reverse proxy?: the other half of what Nginx does, with a working example.
- How to fix 502 Bad Gateway: the Nginx error you are most likely to meet, and how to trace it.
- What is a server?: the bigger picture of what Nginx runs on.
Something out of date? Software changes. If a step no longer works, tell us and we will check it and update the page.


