Introduction to Nginx
Nginx (pronounced “engine‑ex”) is a high‑performance web server and reverse proxy that has gained popularity for its ability to handle thousands of simultaneous connections with low resource consumption. Originally created by Igor Sysoev in 2004 to solve the problem of traditional web servers under heavy loads, today Nginx powers a significant portion of the world’s most‑visited sites. In this article you will learn how to install it on a Linux distribution, configure it as a static web server, use it as a reverse proxy, and apply it as a load balancer, plus review security best practices.
Installation on Linux
The easiest way to install Nginx on Debian/Ubuntu‑based distributions is via the APT package manager:
- Update the package index:
sudo apt update - Install Nginx:
sudo apt install nginx - Verify the service is active:
systemctl status nginx
On RHEL/CentOS/Fedora distributions you use DNF or YUM:
- Install the EPEL repository (if needed):
sudo dnf install epel-release - Install Nginx:
sudo dnf install nginx - Enable and start the service:
sudo systemctl enable --now nginx
After installation, port 80 (HTTP) and, if SSL is enabled, port 443 (HTTPS) will be open by default. You can test it by accessing http://your_ip_or_domain from a browser and you should see the Nginx welcome page.
Basic configuration as a static web server
Nginx configuration files are located in /etc/nginx/. The main file is nginx.conf, but the most common practice is to create server blocks inside /etc/nginx/sites-available/ and symlink them to /etc/nginx/sites-enabled/.
Example of a simple site serving static files from /var/www/my-site:
server {
listen 80;
server_name example.com www.example.com;
root /var/www/my-site;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
After creating or editing the file, check the syntax with sudo nginx -t and reload the configuration: sudo systemctl reload nginx.
Use as a reverse proxy
One of Nginx’s most powerful uses is to act as an intermediary between the client and one or more backend applications (for example, a Node.js server, Python/Flask, or a REST API). In this role, Nginx receives the HTTP request, forwards it to the backend process, and returns the response to