Nginx Service Guide
9/1/26Less than 1 minute
Nginx Service Guide
Nginx is a high-performance HTTP and reverse proxy server, widely used for static site hosting, reverse proxying and load balancing.
Installing Nginx
On Debian/Ubuntu
sudo apt update
sudo apt install nginxOn CentOS/RHEL
sudo yum install nginxStarting and Managing Nginx
sudo systemctl start nginx
sudo systemctl enable nginx
sudo systemctl status nginxReload configuration without downtime:
sudo nginx -s reloadTest configuration before reloading:
sudo nginx -tConfiguration Structure
- Main configuration file:
/etc/nginx/nginx.conf - Site configurations:
/etc/nginx/conf.d/*.confor/etc/nginx/sites-enabled/*
Hosting a Static Site
server {
listen 80;
server_name example.com;
root /var/www/site;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}Reverse Proxy
server {
listen 80;
server_name api.example.com;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}Common Practices
- Use
nginx -tto validate configuration before reloading - Enable gzip compression for static assets
- Set proper cache headers for static resources
