Nginx的启动,停止和重启

冷不防 2022-07-16 20:07 386阅读 0赞

1、Nginx的启动

  1. #nginx启动的命令格式
  2. # -c 指定配置文件的地址
  3. nginx可执行文件的目录 -c n ginx的配置文件
  4. #命令如下
  5. [root@localhost sbin]# ./nginx -c /javasoft/nginx/conf/nginx.conf

2、Nginx的停止

Nginx服务器启动之后,要想让其停止运行,有三种方式。1.从容停止 2.快速停止 3.强制停止

1、从容停止

  1. 1、查看Nginx的主进程号
  2. [root@localhost sbin]# ps -ef | grep nginx
  3. root 7334 1 0 04:19 ? 00:00:00 nginx: master process ./nginx -c /usr/local/nginx/conf/nginx.conf
  4. nobody 7335 7334 0 04:19 ? 00:00:00 nginx: worker process
  5. root 30463 2665 0 04:29 pts/0 00:00:00 grep nginx
  6. 2、停止Nginx
  7. [root@localhost sbin]# kill -QUIT 7334

2、快速停止

  1. 1、查看Nginx的主进程号
  2. [root@localhost sbin]# ps -ef | grep nginx
  3. root 30492 1 0 04:34 ? 00:00:00 nginx: master process ./nginx -c /usr/local/nginx/conf/nginx.conf
  4. nobody 30493 30492 0 04:34 ? 00:00:00 nginx: worker process
  5. root 30504 2665 0 04:37 pts/0 00:00:00 grep nginx
  6. 2、停止Nginx
  7. [root@localhost sbin]# kill -TERM 30492

3、强制停止

  1. 1、查看Nginx的进程号
  2. [root@localhost sbin]# ps -ef | grep nginx
  3. root 30521 1 0 04:40 ? 00:00:00 nginx: master process ./nginx -c /usr/local/nginx/conf/nginx.conf
  4. nobody 30522 30521 0 04:40 ? 00:00:00 nginx: worker process
  5. root 30533 2665 0 04:41 pts/0 00:00:00 grep nginx
  6. 2、停止Nginx
  7. [root@localhost sbin]# kill -9 30521

3、Nginx的重启

Nginx服务器在运行的时候,若想对其进行重新启动,比如当我们修改了配置文件,需要让新配置文件生效,就得重启等。当然重启的原因有很多,让新配置文件生效只是重启的其中一个原因。下面我们通过实例来讲解一下具体如何重启。

  1. 1、修改了配置文件后,先验证了配置文件的正确性,再重新启动
  2. 1.1 第一个方法(\-t理解为test,用于测试配置文件的正确性)
  3. [root@localhost sbin]# ./nginx -t
  4. nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
  5. nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
  6. 1.2 第二个方法
  7. [root@localhost /]# /usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
  8. nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
  9. nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
  10. 2、在配置文件的正确性下,重启Nginx服务器
  11. 1.1 第一个方法
  12. [root@localhost sbin]# ./nginx -s reload
  13. 1.2 第二个方法
  14. 1、查询Nginx的信号量
  15. [root@localhost sbin]# ps -ef | grep nginx
  16. root 30657 1 0 04:56 ? 00:00:00 nginx: master process ./nginx
  17. nobody 30662 30657 0 04:56 ? 00:00:00 nginx: worker process
  18. root 30669 2665 0 04:57 pts/0 00:00:00 grep nginx
  19. 2、发送信号量,重启Nginx服务。以便于加载修改的配置文件的内容
  20. [root@localhost sbin]# kill -HUP 30657

4、Nginx的启动,停止和重启的另一种方式

  1. #Nginx启动的一个方式
  2. nginx -s stop / start / reload

5、Nginx的信号量

  1. 1Nginx的信号控制概述

上面我们实现的Nginx服务器的启动、停止以及重启是用信号来控制的。这是一些简单的信号控制。在Nginx服务器中,通常情况都是通过对其发送控制信号进行控制的,除了以上所说的简单的信号控制之外,还有很多的信号控制。在此,我们需要知道,要想操作Nginx服务器,一般来说是对其发送信号来对其进行控制。

  1. 2Nginx常见的信号控制实战
  2. 下面我们通过实例对Nginx常见的信号控制命令进行实战讲解
  3. 1HUP 重启
  4. 2QUIT 从容重启
  5. 3TERM 快速关闭
  6. 4INT 从容关闭
  7. 5USR1 切换日志文件(用于切换日志文件和切割日志文件)
  8. 6USR2 平滑升级可执行进行
  9. 7WINCH 从容关闭工作进程

2、Nginx常见的信号控制实战

下面我们通过实例对Nginx常见的信号控制命令进行实战讲解

1、HUP 重启

2、QUIT 从容重启

3、TERM 快速关闭

4、INT 从容关闭

5、USR1 切换日志文件(用于切换日志文件和切割日志文件)

6、USR2 平滑升级可执行进行

7、WINCH 从容关闭工作进程

发表评论

表情:
评论列表 (有 0 条评论,386人围观)

还没有评论,来说两句吧...

相关阅读