System
nginx CLI
nginx commands for web server management and configuration.
30 commands
Windows
MacOS
Linux
#web-server
#reverse-proxy
Service Control
Start nginx with default configuration
nginx
Stop nginx immediately
nginx -s stop
Gracefully shut down nginx
nginx -s quit
Reload configuration without downtime
nginx -s reload
Reopen log files for rotation
nginx -s reopen
Check nginx service status
systemctl status nginx
Enable nginx to start on boot
systemctl enable nginx
Configuration
Test configuration for syntax errors
nginx -t
Test and dump the full configuration
nginx -T
Start with a custom config file
nginx -c /etc/nginx/custom.conf
Show compile-time configuration options
nginx -V
Set global directives from command line
nginx -g 'worker_processes 4;'
Testing
Validate config file syntax
nginx -t
Check response headers from nginx
curl -I http://localhost
Test HTTPS ignoring certificate errors
curl -k https://localhost
curl -H 'Host: example.com' http://localhost # Test virtual host routing
Benchmark with Apache Bench
ab -n 1000 -c 100 http://localhost/
Logs
Follow access log in real time
tail -f /var/log/nginx/access.log
Follow error log in real time
tail -f /var/log/nginx/error.log
Top client IPs
awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head
Top requested URLs
awk '{print $7}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head
Filter 5xx server error entries
awk '$9 >= 500' /var/log/nginx/access.log
SSL Setup
Generate self-signed cert for nginx
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/self.key -out /etc/nginx/ssl/self.crt
Obtain Let's Encrypt certificate for nginx
certbot --nginx -d example.com
Test certificate renewal process
certbot renew --dry-run
Generate DH parameters for stronger SSL
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
List all managed certificates and expiry
certbot certificates
Quick Commands
Test nginx configuration for syntax errors
nginx -t
Reload nginx configuration without downtime
nginx -s reload
Obtain and install a Let's Encrypt SSL certificate
certbot --nginx -d example.com