Commandes CLI NGINX, gestion de serveurs web, configuration, virtual hosts, reverse proxy, SSL, monitoring et optimisation des performances. Guide pratique pour développeurs, DevOps et administrateurs système.
nginx
Démarre le serveur Nginx
-c--conf-path-g--global-directives-p--prefix-q--quiet-s--signal-t--test-T--test-config-v--version-V--verbose-version-h--help-?-e--error-log-path
nginx -s stop
Arrête Nginx rapidement
-s
nginx -s quit
Arrête Nginx gracieusement (attend la fin des requêtes)
-s
nginx -s reload
Recharge la configuration sans interruption
-s
nginx -s reopen
Rouvre les fichiers de logs
-s
nginx -t
Teste la configuration et quitte
-t
nginx -T
Teste la configuration et affiche la configuration complète
-T
nginx -v
Affiche la version de Nginx
-v
nginx -V
Affiche la version et les options de compilation
-V
nginx -c /etc/nginx/nginx.conf
Démarre avec un fichier de configuration spécifique
-c--conf-path
nginx -g "daemon off;"
Démarre avec des directives globales (ex: foreground)
-g--global-directives
nginx -g "worker_processes 4;"
Définit le nombre de workers
-g
nginx -p /custom/prefix
Définit le préfixe de chemin
-p--prefix
nginx -e /var/log/nginx/error.log
Spécifie le fichier de log d'erreur
-e--error-log-path
nginx -q
Mode silencieux (supprime les messages non critiques)
-q--quiet
systemctl start nginx
Démarre Nginx via systemd
systemctl stop nginx
Arrête Nginx via systemd
systemctl restart nginx
Redémarre Nginx via systemd
systemctl reload nginx
Recharge la configuration via systemd
systemctl status nginx
Affiche le statut de Nginx
systemctl enable nginx
Active Nginx au démarrage
systemctl disable nginx
Désactive Nginx au démarrage
service nginx start
Démarre Nginx via SysVinit
service nginx stop
Arrête Nginx via SysVinit
service nginx restart
Redémarre Nginx via SysVinit
service nginx reload
Recharge la configuration via SysVinit
service nginx status
Affiche le statut via SysVinit
/etc/init.d/nginx start
Démarre Nginx via script init.d
stoprestartreloadstatus
nginx -s stop && nginx
Redémarrage dur (stop puis start)
kill -HUP $(cat /var/run/nginx.pid)
Recharge la configuration via signal HUP
kill -QUIT $(cat /var/run/nginx.pid)
Arrêt gracieux via signal QUIT
kill -TERM $(cat /var/run/nginx.pid)
Arrêt rapide via signal TERM
kill -USR1 $(cat /var/run/nginx.pid)
Rouvre les fichiers de logs via signal USR1
kill -USR2 $(cat /var/run/nginx.pid)
Mise à niveau binaire sans interruption
kill -WINCH $(cat /var/run/nginx.pid)
Arrêt gracieux des workers
nginx -t && nginx -s reload
Teste puis recharge la configuration
tail -f /var/log/nginx/access.log
Surveille le log d'accès en temps réel
-f-n
tail -f /var/log/nginx/error.log
Surveille le log d'erreur en temps réel
-f-n
tail -n 100 /var/log/nginx/access.log
Affiche les 100 dernières lignes du log d'accès
-n
grep "404" /var/log/nginx/access.log
Recherche les erreurs 404 dans les logs
-c-v-i-A-B
grep -c "GET" /var/log/nginx/access.log
Compte le nombre de requêtes GET
-c
awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head -10
Top 10 des IP les plus actives
awk '{print $7}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head -10
Top 10 des URLs les plus demandées
cat /var/log/nginx/access.log | wc -l
Compte le nombre total de requêtes
logrotate -f /etc/logrotate.d/nginx
Force la rotation des logs Nginx
-f-d-v
logrotate -d /etc/logrotate.d/nginx
Teste la rotation des logs (dry run)
-d
mv /var/log/nginx/access.log /var/log/nginx/access.log.old && nginx -s reopen
Rotation manuelle des logs
goaccess /var/log/nginx/access.log
Analyse les logs avec GoAccess (interface interactive)
-f--log-format-o--output--real-time-html--ws-url
goaccess /var/log/nginx/access.log -o report.html --log-format=COMBINED
Génère un rapport HTML avec GoAccess
-o--log-format
goaccess /var/log/nginx/access.log --real-time-html -o /var/www/html/report.html
Rapport en temps réel
--real-time-html-o
nginx -t 2>&1 | grep -i error
Teste la configuration et affiche uniquement les erreurs
nginx -T | grep server_name
Affiche tous les server_name configurés
nginx -T | grep -A5 "location"
Affiche les blocs location avec contexte
nginx -T | grep -E "listen|server_name"
Affiche les ports et noms de domaine
ps aux | grep nginx
Affiche les processus Nginx en cours
ps -ef | grep nginx
Affiche les processus Nginx (format détaillé)
pgrep nginx
Affiche les PID des processus Nginx
-l-a-f
netstat -tulpn | grep nginx
Affiche les ports en écoute par Nginx
-tulpn-tulpn | grep :80
ss -tulpn | grep nginx
Affiche les sockets Nginx (alternative à netstat)
-tulpn
lsof -i :80
Affiche le processus utilisant le port 80
-i
lsof -i :443
Affiche le processus utilisant le port 443
-i
curl -I http://localhost
Teste l'en-tête HTTP du serveur local
-I-v-X-H-d
curl -v http://localhost
Teste avec détails de la requête/réponse
-v
curl -H "Host: example.com" http://localhost
Teste avec un Host header personnalisé
-H
curl -X POST -d "data=test" http://localhost/api
Teste une requête POST
-X-d--data
wget --spider http://localhost
Vérifie si le serveur répond (spider)
--spider-S--server-response
ab -n 1000 -c 10 http://localhost/
Benchmark avec Apache Bench (1000 requêtes, 10 concurrentes)
-n-c-t-k-H-p-T-g-e
ab -n 10000 -c 100 -t 30 http://localhost/
Benchmark limité à 30 secondes
-t
wrk -t 4 -c 100 -d 30s http://localhost/
Benchmark avec wrk (4 threads, 100 connexions, 30s)
-t-c-d-s-H--latency
wrk -t 4 -c 100 -d 30s --latency http://localhost/
Benchmark avec statistiques de latence
--latency
siege -c 50 -t 30s http://localhost/
Benchmark avec Siege (50 utilisateurs, 30 secondes)
-c-t-r-d-f-i-b-g-H
siege -c 100 -r 10 http://localhost/
100 utilisateurs, 10 répétitions chacun
-c-r
hey -n 10000 -c 100 http://localhost/
Benchmark avec Hey (10k requêtes, 100 concurrentes)
-n-c-q-t-z-m-H-T-a-d-o
vegeta attack -rate=100 -duration=30s -targets=targets.txt | vegeta report
Benchmark avec Vegeta (100 req/s pendant 30s)
attackreportplotencodedecode
echo "GET http://localhost/" | vegeta attack -rate=100 -duration=10s | vegeta report
Test simple avec Vegeta
htop -p $(pgrep -d',' nginx)
Surveille les processus Nginx avec htop
strace -p $(cat /var/run/nginx.pid) -f -e trace=network
Trace les appels réseau de Nginx
-p-f-e
strace -p $(pgrep nginx | head -1) -c
Statistiques des appels système
-p-c
tcpdump -i any port 80 -A
Capture le trafic HTTP sur le port 80
-iport-A-w-r-c-n-v
tcpdump -i any port 443 -w nginx.pcap
Capture le trafic HTTPS dans un fichier
-iport-w
openssl s_client -connect localhost:443 -servername example.com
Teste la connexion SSL/TLS avec SNI
-connect-servername-showcerts-debug-state-tls1_2-tls1_3
openssl s_client -connect localhost:443 -showcerts
Affiche la chaîne de certificats
-showcerts
echo | openssl s_client -connect localhost:443 2>/dev/null | openssl x509 -noout -dates
Affiche les dates de validité du certificat
openssl dhparam -out /etc/nginx/dhparam.pem 2048
Génère les paramètres Diffie-Hellman
-out20484096
openssl req -new -newkey rsa:2048 -nodes -keyout server.key -out server.csr
Génère une CSR (Certificate Signing Request)
-new-newkey-nodes-keyout-out-subj-days-x509
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout server.key -out server.crt
Génère un certificat auto-signé
-x509-nodes-days-newkey-keyout-out
certbot --nginx -d example.com -d www.example.com
Obtient un certificat Let's Encrypt avec Certbot
--nginx-d--email--agree-tos--non-interactive--redirect--staging--dry-run--expand--renew-by-default--force-renewal--test-cert
certbot --nginx -d example.com --dry-run
Teste l'obtention du certificat (dry run)
--dry-run
certbot renew
Renouvelle tous les certificats
--dry-run--force-renewal--quiet--post-hook
certbot renew --post-hook "nginx -s reload"
Renouvelle et recharge Nginx
--post-hook
certbot certificates
Liste les certificats gérés par Certbot
certbot delete --cert-name example.com
Supprime un certificat
--cert-name
certbot revoke --cert-path /etc/letsencrypt/live/example.com/cert.pem
Révoque un certificat
--cert-path--key-path--reason
certbot enhance --nginx -d example.com
Améliore la configuration SSL (HSTS, OCSP, etc.)
--nginx-d
certbot install --cert-name example.com
Installe un certificat existant
--cert-name
certbot register --email admin@example.com --agree-tos
Enregistre un compte Let's Encrypt
--email--agree-tos--no-eff-email--eff-email
certbot unregister
Désenregistre le compte Let's Encrypt
certbot update_account --email new@example.com
Met à jour l'email du compte
--email
certbot config_changes --num 5
Affiche les 5 derniers changements de configuration
--num
certbot rollback --checkpoint 5
Revient à une configuration précédente
--checkpoint
certbot-plugin-gandi
Plugin Certbot pour Gandi DNS
--dns-gandi--dns-gandi-credentials
certbot certonly --dns-cloudflare --dns-cloudflare-credentials /path/to/credentials.ini -d example.com
Certificat via DNS Cloudflare
certonly--dns-cloudflare--dns-cloudflare-credentials
certbot certonly --standalone -d example.com
Certificat en mode standalone (serveur temporaire)
certonly--standalone--standalone-supported-challenges
certbot certonly --webroot -w /var/www/html -d example.com
Certificat via webroot
certonly--webroot-w
certbot certonly --manual -d example.com
Certificat en mode manuel
certonly--manual--manual-auth-hook--manual-cleanup-hook
certbot certonly --dns-route53 -d example.com
Certificat via DNS AWS Route53
certonly--dns-route53
certbot certonly --dns-google -d example.com
Certificat via DNS Google Cloud
certonly--dns-google--dns-google-credentials
certbot certonly --dns-digitalocean -d example.com
Certificat via DNS DigitalOcean
certonly--dns-digitalocean--dns-digitalocean-credentials
certbot certonly --dns-linode -d example.com
Certificat via DNS Linode
certonly--dns-linode--dns-linode-credentials
certbot certonly --dns-ovh -d example.com
Certificat via DNS OVH
certonly--dns-ovh--dns-ovh-credentials
certbot certonly --preferred-challenges dns -d example.com
Préfère le challenge DNS
--preferred-challenges
certbot certonly --rsa-key-size 4096 -d example.com
Utilise une clé RSA 4096 bits
--rsa-key-size--key-type
certbot certonly --key-type ecdsa -d example.com
Utilise une clé ECDSA
--key-type
certbot certonly --elliptic-curve secp384r1 -d example.com
Spécifie la courbe elliptique
--elliptic-curve
certbot certonly --must-staple -d example.com
Ajoute l'extension OCSP Must-Staple
--must-staple
certbot certonly --reuse-key -d example.com
Réutilise la clé existante lors du renouvellement
--reuse-key
certbot certonly --no-random-sleep-on-renew
Désactive la pause aléatoire au renouvellement
--no-random-sleep-on-renew
certbot certonly --allow-subset-of-names -d example.com,www.example.com
Autorise un sous-ensemble de noms
--allow-subset-of-names
certbot certonly --keep-until-expiring -d example.com
Garde le certificat jusqu'à expiration
--keep-until-expiring--keep--renew-with-new-domains
certbot certonly --force-renewal -d example.com
Force le renouvellement
--force-renewal
certbot certonly --break-my-certs -d example.com
Force le renouvellement même si cassé
--break-my-certs
certbot certonly --test-cert -d example.com
Utilise le serveur de test (staging)
--test-cert--staging
certbot certonly --server https://acme-v02.api.letsencrypt.org/directory
Spécifie le serveur ACME
--server
certbot certonly --eab-kid <kid> --eab-hmac-key <key>
Utilise l'authentification External Account Binding
--eab-kid--eab-hmac-key
certbot certonly --user-agent "MyAgent/1.0"
Personnalise le User-Agent
--user-agent
certbot certonly --max-log-backups 5
Nombre de sauvegardes de logs
--max-log-backups
certbot certonly --logs-dir /custom/logs
Dossier personnalisé pour les logs
--logs-dir
certbot certonly --config-dir /custom/config
Dossier de configuration personnalisé
--config-dir
certbot certonly --work-dir /custom/work
Dossier de travail personnalisé
--work-dir
certbot certonly --http-01-port 8080
Port personnalisé pour le challenge HTTP-01
--http-01-port
certbot certonly --http-01-address 0.0.0.0
Adresse d'écoute pour le challenge HTTP-01
--http-01-address
certbot certonly --tls-sni-01-port 8443
Port pour le challenge TLS-SNI-01 (déprécié)
--tls-sni-01-port
certbot certonly --preferred-chain "ISRG Root X1"
Chaîne de certificats préférée
--preferred-chain
certbot certonly --deploy-hook "nginx -s reload"
Hook exécuté après déploiement réussi
--deploy-hook
certbot certonly --pre-hook "systemctl stop nginx" --post-hook "systemctl start nginx"
Hooks avant/après renouvellement
--pre-hook--post-hook
certbot certonly --renew-hook "nginx -s reload"
Hook exécuté après renouvellement
--renew-hook
certbot certonly --manual-auth-hook /path/to/auth.sh --manual-cleanup-hook /path/to/cleanup.sh
Hooks pour validation manuelle
--manual-auth-hook--manual-cleanup-hook
certbot certonly --installer nginx
Spécifie l'installer Nginx
--installer
certbot certonly --authenticator standalone
Spécifie l'authenticator
--authenticator
certbot certonly --nginx-ctl /usr/local/nginx/sbin/nginx
Chemin personnalisé vers l'exécutable Nginx
--nginx-ctl
certbot certonly --nginx-server-root /custom/conf.d
Dossier de configuration Nginx personnalisé
--nginx-server-root
certbot certonly --nginx-sleep-seconds 1
Délai après rechargement Nginx
--nginx-sleep-seconds
certbot renew --dry-run
Teste le renouvellement
--dry-run
certbot renew --force-renewal
Force le renouvellement de tous les certificats
--force-renewal
certbot renew --cert-name example.com
Renouvelle un certificat spécifique
--cert-name
certbot renew --no-random-sleep-on-renew
Sans pause aléatoire
--no-random-sleep-on-renew
certbot renew --disable-hook-validation
Désactive la validation des hooks
--disable-hook-validation
certbot renew --break-my-certs
Force le renouvellement même si cassé
--break-my-certs
certbot revoke --cert-name example.com --reason keycompromise
Révoque un certificat (raison: compromission)
--cert-name--reason
certbot revoke --cert-path /path/to/cert.pem --key-path /path/to/key.pem --no-delete-after-revoke
Révoque sans supprimer les fichiers
--cert-path--key-path--no-delete-after-revoke
certbot delete --cert-name example.com
Supprime un certificat
--cert-name
certbot unregister --email admin@example.com
Désenregistre un compte
--email
certbot register --update-registration --email new@example.com
Met à jour l'email d'enregistrement
--update-registration--email
certbot plugins
Liste les plugins disponibles
--init--prepare--authenticators--installers
certbot config_changes --num 10
Affiche les 10 derniers changements
--num
certbot rollback --checkpoint 3
Revient au checkpoint 3
--checkpoint
certbot show_account
Affiche les détails du compte
certbot certonly --csr /path/to/domain.csr
Utilise une CSR existante
--csr
certbot certonly --fullchain-path /path/to/fullchain.pem --chain-path /path/to/chain.pem --key-path /path/to/privkey.pem
Chemins personnalisés pour les fichiers
--fullchain-path--chain-path--key-path
certbot certonly --duplicate
Crée un certificat en double
--duplicate
certbot certonly --force-renewal --no-random-sleep-on-renew
Renouvellement forcé sans pause
--force-renewal--no-random-sleep-on-renew
certbot certonly --quiet
Mode silencieux
--quiet-q
certbot certonly --non-interactive
Mode non interactif
--non-interactive-n
certbot certonly --agree-tos --email admin@example.com --non-interactive
Accepte les conditions automatiquement
--agree-tos--email--non-interactive
certbot certonly --no-eff-email
Ne partage pas l'email avec l'EFF
--no-eff-email--eff-email
certbot certonly --verbose
Mode verbeux
--verbose-v
certbot certonly --debug
Mode debug
--debug
certbot certonly --config /custom/cli.ini
Fichier de configuration personnalisé
--config
certbot certonly --user-agent "MyCustomAgent/2.0"
User-Agent personnalisé
--user-agent
certbot certonly --http-01-port 80 --tls-sni-01-port 443
Ports personnalisés pour les challenges
--http-01-port--tls-sni-01-port
certbot certonly --domain example.com --domain www.example.com --domain api.example.com
Plusieurs domaines dans un certificat
-d--domain
certbot certonly -d "*.example.com" -d example.com --dns-cloudflare
Certificat wildcard (*.example.com)
-d--dns-cloudflare
certbot certonly -d example.com --register-unsafely-without-email
Enregistrement sans email (déconseillé)
--register-unsafely-without-email
certbot renew --cert-name example.com --deploy-hook "nginx -s reload"
Renouvelle et recharge Nginx
--cert-name--deploy-hook
certbot renew --pre-hook "systemctl stop nginx" --post-hook "systemctl start nginx"
Arrête/redémarre Nginx pendant le renouvellement
--pre-hook--post-hook
certbot renew --renew-hook "/usr/local/bin/renew-notify.sh"
Hook personnalisé après renouvellement
--renew-hook
certbot renew --no-self-upgrade
Désactive l'auto-mise à jour de Certbot
--no-self-upgrade
certbot renew --max-log-backups 10
Conserve 10 sauvegardes de logs
--max-log-backups
certbot certonly --keep --renew-with-new-domains -d example.com -d new.example.com
Garde le certificat existant et ajoute un domaine
--keep--renew-with-new-domains
certbot certonly --allow-subset-of-names -d example.com,www.example.com,api.example.com
Autorise un sous-ensemble de domaines validés
--allow-subset-of-names
certbot certonly --preferred-challenges dns-01
Préfère le challenge DNS-01
--preferred-challenges
certbot certonly --preferred-challenges http-01,tls-alpn-01
Plusieurs challenges préférés
--preferred-challenges
certbot certonly --validate-hooks
Valide les hooks avant exécution
--validate-hooks
certbot certonly --disable-hook-validation
Désactive la validation des hooks
--disable-hook-validation
certbot certonly --staple-ocsp
Active l'agrafage OCSP
--staple-ocsp
certbot certonly --must-staple
Exige l'agrafage OCSP
--must-staple
certbot certonly --reuse-key
Réutilise la clé existante
--reuse-key
certbot certonly --new-key
Génère une nouvelle clé (par défaut)
--new-key
certbot certonly --key-type rsa --rsa-key-size 3072
Clé RSA 3072 bits
--key-type--rsa-key-size
certbot certonly --key-type ecdsa --elliptic-curve secp256r1
Clé ECDSA avec courbe P-256
--key-type--elliptic-curve
certbot certonly --elliptic-curve secp384r1
Courbe P-384
--elliptic-curve
certbot certonly --key-type ed25519
Clé Ed25519
--key-type
certbot certonly --chain "ISRG Root X1"
Chaîne de certificats préférée
--chain
certbot certonly --no-directory-hooks
Désactive les hooks par répertoire
--no-directory-hooks
certbot certonly --directory-hooks
Active les hooks par répertoire (défaut)
--directory-hooks
certbot certonly --no-autorenew
Désactive le renouvellement automatique
--no-autorenew
certbot certonly --autorenew
Active le renouvellement automatique (défaut)
--autorenew
certbot certonly --no-redirect
Désactive la redirection HTTP vers HTTPS
--no-redirect
certbot certonly --redirect
Active la redirection HTTP vers HTTPS
--redirect
certbot certonly --no-ask-enter --non-interactive --agree-tos --email admin@example.com -d example.com
Commande complète non interactive
--no-ask-enter--non-interactive--agree-tos--email-d