| name | nginx |
| description | Nginx configuration, reverse proxy, and SSL |
| metadata | {"openclaw":{"always":false,"emoji":"🌍"}} |
Nginx
Nginx management: configuration, reverse proxy, SSL.
Setup
command -v nginx
brew install nginx
sudo apt install nginx
Basic Commands
sudo nginx -t
sudo systemctl reload nginx
sudo systemctl restart nginx
systemctl status nginx
nginx -V
Logs
sudo tail -f /var/log/nginx/access.log
sudo tail -100 /var/log/nginx/access.log
sudo tail -f /var/log/nginx/error.log
sudo tail -f /var/log/nginx/<site>-access.log
Site Configuration
ls /etc/nginx/sites-available/
ls /etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/<site> /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
sudo rm /etc/nginx/sites-enabled/<site>
sudo nginx -t && sudo systemctl reload nginx
Reverse Proxy (template)
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;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
SSL with Certbot
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d example.com
sudo certbot renew --dry-run
sudo certbot renew
WebSocket Proxy
location /ws {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
Tips
- Always run
nginx -t before reload/restart
- Use
sites-available + symlink to sites-enabled
- For debug:
error_log /var/log/nginx/debug.log debug;
- Rate limiting:
limit_req_zone in the http section
- Gzip: enable in
/etc/nginx/nginx.conf for performance