Nginx 常用命令

292 阅读1分钟

1.使用nginx操作命令前提

使用nginx操作命令前提:必须进入到nginx的自动生成目录的下/sbin文件夹下。

nginx有两个目录:

  • 第一个:安装目录,我放在:
/opt/nginx
  • 第二个:自动生成目录:
/usr/local/nginx

2.启动Nginx

默认以nginx目录配置文件nginx.conf启动:

nginx

指定配置文件启动:

nginx -c /opt/wyl/a.conf

3.停止Nginx

-s 表示向 nginx 发送信号, s 是 signal 的简写。

  1. 立即停止nginx
nginx -s stop
  1. 优雅停止nginx 会处理完当前连接后停止
nginx -s quit

4.重新加载配置文件

默认是nginx目录下的配置文件nginx.conf

nginx -s reload

指定配置文件

nginx -c /opt/wyl/a.conf -s reload

5.重启nginx

nginx -s reopen

6.查看Nginx版本

显示nginx版本

nginx -v

显示nginx版本及编译时的配置选项

nginx -V

7.查看nginx配置

nginx -T         # 查看当前 Nginx 最终的配置
nginx -t -c <配置路径>    # 检查配置是否有问题,如果已经在配置目录,则不需要-c

8.systemctl

systemctl 是 Linux 系统应用管理工具 systemd 的主命令,用于管理系统,我们也可以用它来对 Nginx 进行管理,相关命令如下:

systemctl start nginx    # 启动 Nginx
systemctl stop nginx     # 停止 Nginx
systemctl restart nginx  # 重启 Nginx
systemctl reload nginx   # 重新加载 Nginx,用于修改配置后
systemctl enable nginx   # 设置开机启动 Nginx
systemctl disable nginx  # 关闭开机启动 Nginx
systemctl status nginx   # 查看 Nginx 运行状态