Nginx 的常用命令
2025/6/9小于 1 分钟
Nginx 常用命令
1. 查看 Nginx 版本
nginx -v输出示例:
nginx version: nginx/1.24.02. 启动 Nginx
nginx默认会读取
/usr/local/nginx/conf/nginx.conf配置文件。
如需指定配置文件:
nginx -c /path/to/nginx.conf3. 停止 Nginx
快速关闭(不保存连接):
nginx -s stop优雅关闭(处理完当前连接):
nginx -s quit
4. 重新加载配置(不中断服务)
nginx -s reload修改配置文件后,使用此命令应用新配置。
5. 检查配置文件是否有语法错误
nginx -t输出示例:
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful6. 查看 Nginx 进程状态(Linux)
ps -ef | grep nginx或使用:
pidof nginx7. 强制杀死 Nginx 所有进程(慎用)
killall -9 nginxNginx 启动失败怎么办?
执行:
nginx -t检查配置语法是否正确,并确认端口未被占用。
2. 80端口被占用怎么办?
lsof -i :80
kill -9 <PID>