04 Nginx操作的常用命令

1
2
3
4
5
6
7
8
9
# 查看 Nginx 版本
[root@VM_0_7_centos ~]# nginx -v
nginx version: nginx/1.16.1
# 启动 Nginx
[root@VM_0_7_centos ~]# nginx
# 停止 Nginx
[root@VM_0_7_centos ~]# nginx -s stop
# 重启 Nginx
[root@VM_0_7_centos ~]# nginx -s reload

Nginx在运行时,会保持一个主进程和一个或多个 worker process 进程.通过给主进程发送信号即可控制服务的启停

Nginx 服务器可以接受的信号:

信号 作用
TERMINT 快速停止 Nginx 服务
QUIT 平缓停止 Nginx 服务
HUB 使用新的配置文件启动进程,之后平缓停止原有进程.也就是”平滑重启”
USR1 重新打开日志文件,常用语日志切割.
USR2 使用新版本的 Nginx 文件启动服务,之后平缓停止原有 Nginx 进程,也就是”平滑升级”
WINCH 平缓停止 worker process ,用于 Nginx 服务器平滑升级

Nginx 服务器发送信号的方法:

  • 使用 Nginx 二进制文件

    1
    nginx -s stop | quit | reopen | reload
  • 使用 kill 命令发送信号(不推荐)

    1
    2
    3
    4
    # SIGNAL:用于指定信号		PID:Nginx 主进程的 PID
    kill SIGNAL PID
    # filepath 为 nginx.pid 的路径 (/run/nginx.pid)
    kill SIGNAL `filepath`

    223.104.37.137

评论

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×