首页 > 编程知识 正文

nginx 的启动停止与重启 nginx进程杀死后pid丢

时间:2023-05-06 06:02:04 阅读:228519 作者:200

sudo vim nginx.conf

详解 ./nginx #打开 nginxnginx -s reload|reopen|stop|quit #重新加载配置|重启|停止|退出 nginxnginx -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 SIGHUPSIGNALS 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 asjdl. SIGWINCH Shut down worker processes gracefully. 停止 查看进程号: $ ps -ef|grep nginxroot 5747 1 0 May23 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx 12037 7886 0 10:00 pts/1 00:00:00 grep nginxnobody 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

进程性的 nginx -s stop后再次启动nginx -s reload ,总是会报错误nginx: [error] open() “/alidata/server/nginx/logs/nginx.pid” failed (2: No such file or directory)。
原因:nginx进程杀死后pid丢失了,下一次再开启nginx -s reload时无法启动,重装可以解决问题,做不做,你决定吧,哈哈。

还是英文的解释比较专业:

issued a nginx -s stop and after that I got this error when trying to reload it.
[error]: invalid PID number “” in “/var/run/nginx.pid”
That /var/run/nginx/pid file is empty atm.
What do I need to do to fix it?

nginx -s reload is only used to tell a running nginx process to reload its config. After a stop, you don’t have a running nginx process to send a signal to. Just run nginx (possibly with a -c /path/to/config/file)

使用方法:

nginx -c /path/to/config/file例子 /alidata/server/nginx/sbin/nginx -c /alidata/server/nginx/conf/nginx.conf或者 sudo /data/tengine/sbin/nginx -c /data/tengine/conf/nginx.conf 2. 启动nginx服务 nginx -t -c /usr/nginx/conf/nginx.conf 或者/usr/nginx/sbin/nginx -t

nginx -s reload :修改配置后重新加载生效
nginx -s reopen :重新打开日志文件
nginx -t -c /path/to/nginx.conf 测试nginx配置文件是否正确

启动操作 -c参数指定了要加载的nginx配置文件路径

nginx -c /usr/local/nginx/conf/nginx.conf
停止操作
nginx -s stop :快速停止nginx
quit :完整有序的停止nginx

步骤1:查询nginx主进程号

ps -ef | grep nginx
在进程列表里 面找master进程,它的编号就是主进程号了。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。