1. Basic installation + config
sudo apt update
sudo apt install nginx -y
Main config file:
/etc/nginx/nginx.conf
Sites configs:
/etc/nginx/sites-available/
/etc/nginx/sites-enabled/
Create default reverse proxy config:
sudo nano /etc/nginx/sites-available/proxy.conf
Basic reverse proxy:
server {
listen 80;
server_name _;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
Enable + check:
sudo ln -s /etc/nginx/sites-available/proxy.conf /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
2. Offline documentation install
(чтоб админ мог читать доки без инета)
Install Zeal dev docs (GUI) or dash equivalents:
CLI variant – devdocs offline:
sudo snap install zeal
Or host your own:
https://devdocs.io/offline
Better CLI docs:
sudo apt install -y manpages-dev
sudo apt install -y tldr
tldr nginx
3. Additional PHP extensions
If using nginx + php-fpm:
sudo apt install php php-fpm php-cli php-mysql php-curl php-xml php-zip php-mbstring php-gd php-intl -y
Check PHP-FPM:
systemctl status php*-fpm
Nginx PHP-fpm upstream:
upstream backend-php {
server unix:/run/php/php-fpm.sock;
}
4. Five real proxy cases
4.1 Simple local static webserver
Serves static files + browse directories
server {
listen 80;
root /var/www/files;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
}
4.2 Reverse proxy to internal Apache
Apache listens on 127.0.0.1:8080
server {
listen 80;
location / {
proxy_pass http://127.0.0.1:8080;
}
}
4.3 Proxy w/backend load-balancing
(как твой кейс)
upstream backend {
server 10.0.1.10:2424;
server 10.0.1.11:2424 backup;
}
server {
listen 80;
location / {
proxy_pass http://backend;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
}
}
4.4 Proxy cache for slow backend
(для WordPress, PHP, API – ускоряет админку)
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=mycache:100m inactive=60m;
server {
listen 80;
location / {
proxy_cache mycache;
proxy_pass http://127.0.0.1:9000;
proxy_cache_valid 200 302 10m;
proxy_cache_valid 404 1m;
}
}
5. Troubleshooting
Check syntax:
sudo nginx -t
Logs:
journalctl -xeu nginx
tail -f /var/log/nginx/error.log
Check upstream connectivity:
curl -I http://127.0.0.1:8080
Reload:
sudo systemctl reload nginx