Linux Nginx Guide - ryzendew/Linux-Tips-and-Tricks GitHub Wiki
Linux Nginx Guide
Complete beginner-friendly guide to Nginx on Linux, covering Arch Linux, CachyOS, and other distributions including installation, configuration, and server blocks.
Table of Contents
Nginx Installation
Install Nginx
Arch/CachyOS:
# Install Nginx
sudo pacman -S nginx
# Enable service
sudo systemctl enable --now nginx
# Check status
systemctl status nginx
Debian/Ubuntu:
sudo apt install nginx
sudo systemctl enable nginx
Fedora:
sudo dnf install nginx
sudo systemctl enable nginx
Verify Installation
Test Nginx:
# Check if running
curl http://localhost
# Or open browser
# http://localhost
Nginx Configuration
Main Configuration
Edit config:
# Edit main config
sudo vim /etc/nginx/nginx.conf
Basic Settings
Common settings:
user http;
worker_processes auto;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
}
Server Blocks
Create Server Block
Nginx server block:
# Create server block
sudo vim /etc/nginx/sites-available/example.com
Add:
server {
listen 80;
server_name example.com;
root /srv/http/example;
index index.html;
}
Enable:
# Create symlink
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
# Test config
sudo nginx -t
# Reload
sudo systemctl reload nginx
Reverse Proxy
Configure Proxy
Reverse proxy:
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
Troubleshooting
Nginx Not Starting
Check logs:
# Check service
systemctl status nginx
# Check logs
journalctl -u nginx
# Or error log
sudo tail -f /var/log/nginx/error.log
Test Configuration
Validate config:
# Test configuration
sudo nginx -t
# Reload if OK
sudo systemctl reload nginx
Summary
This guide covered Nginx installation, configuration, and server blocks for Arch Linux, CachyOS, and other distributions.
Next Steps
- Web Servers - Web server setup
- Networking - Network setup
- Nginx: https://nginx.org/
This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.