nginx 的启动、停止与重启
详解
./nginx #打开 nginx nginx -s reload|reopen|stop|quit #重新加载配置|重启|停止|退出 nginx nginx -t #测试配置是否有语法错误 nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives] -?,-h : 打开帮助信息 -v : 显示版本信息并退出 -V : 显示版本和配置选项信息,然后退出 -t : 检测配置文件是否有语法错误,然后退出 -q : 在检测配置文件期间屏蔽非错误信息 -s signal : 给一个 nginx 主进程发送信号:stop(停止), quit(退出), reopen(重启), reload(重新加载配置文件) -p prefix : 设置前缀路径(默认是:/usr/local/nginx/) -c filename : 设置配置文件(默认是:/usr/local/nginx/conf/nginx.conf) -g directives : 设置配置文件外的全局指令
-s signal Send a signal to the master process. The argument signal can be one of: stop, quit, reopen, reload.
The following table shows the corresponding system signals:
stop SIGTERM
quit SIGQUIT
reopen SIGUSR1
reload SIGHUP
SIGNALS
The master process of nginx can handle the following signals:
SIGINT, SIGTERM Shut down quickly.
SIGHUP Reload configuration, start the new worker process with a new configuration, and gracefully shut
down old worker processes.
SIGQUIT Shut down gracefully.
SIGUSR1 Reopen log files.
SIGUSR2 Upgrade the nginx executable on the fly.
SIGWINCH Shut down worker processes gracefully.
停止
查看进程号:
$ ps -ef|grep nginx root 5747 1 0 May23 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx 500 12037 7886 0 10:00 pts/1 00:00:00 grep nginx nobody 25581 5747 0 Sep27 ? 00:01:16 nginx: worker process nobody 25582 5747 0 Sep27 ? 00:01:25 nginx: worker process nobody 25583 5747 0 Sep27 ? 00:02:59 nginx: worker process nobody 25584 5747 0 Sep27 ? 00:02:05 nginx: worker process
杀死进程:
$ kill -9 5747
重启
1. 验证nginx配置文件是否正确
进入nginx安装目录sbin下,输入命令:
$ ./nginx -t
…… nginx.conf syntax is ok
…… nginx.conf test is successful
看到如上显示,说明配置文件正确!
2. 重启nginx服务
进入nginx安装目录sbin下,输入命令:
# ./nginx -s reload 或者 # kill -HUP 5747
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· AI与.NET技术实操系列(六):基于图像分类模型对图像进行分类