Nginx2026-04-15·8 分钟
基本指令
Nginx 常用命令速查:安装验证、配置检查、启动重载、日志定位。
Nginx 基本指令
这份清单覆盖本地开发和线上排障最常用的 Nginx 操作。
1. 查看版本与编译参数
bash
nginx -v
nginx -V-v:只看版本号-V:看版本 + 编译模块 + 配置路径(排查模块能力很有用)
2. 检查配置是否正确
bash
nginx -t如果想指定配置文件:
bash
nginx -t -c /etc/nginx/nginx.conf建议每次改配置后先跑 nginx -t,通过后再重载。
3. 启动、停止、优雅退出
bash
nginx
nginx -s stop
nginx -s quitstop:快速停止quit:优雅退出(等现有连接处理完)
4. 重载配置(不中断服务)
bash
nginx -s reload生产环境最常用命令:修改配置并校验通过后执行重载。
5. 重新打开日志文件
bash
nginx -s reopen日志切割后常用,避免写入旧文件句柄。
6. 结合 systemd 的常见操作
bash
sudo systemctl status nginx
sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl restart nginx
sudo systemctl reload nginx
sudo systemctl enable nginxreload:推荐优先使用,影响更小restart:会重启进程,适合异常恢复
7. 常见日志查看
bash
tail -f /var/log/nginx/access.log
tail -f /var/log/nginx/error.log排查 502/504 时,通常先看 error.log。
8. 常见排错顺序
nginx -t看配置语法systemctl status nginx看进程状态tail -f error.log看实时报错- 检查 upstream 服务是否可达(端口、DNS、防火墙)
Nginx运维指令速查