【Nginx】Nginx operation command

1.Nginx native commands

  • 1.1 Official documentation

    ❤️ For complete native command parameters, you can view the Nginx official documentation
    Nginx official command-line parameters
    are as shown below:
    Insert image description here

  • 1.2 Find the command execution file

    The Nginx command execution console, or command execution file, is unified. It was already there when we installed it. The directory is: /usr /sbin/
    Nginx command execution file
    The green one here is, and there is also a debug command execution file.

    When we use a native command, we need to first switch to the directory where the command execution file is located.
    If you forget the installation-related address of Nginx, you can also use the command to find it:
    Insert image description here

  • 1.3 Introduction to basic operation commands

    • 1.3.1 Command help

      nginx -? 或 nginx -h
      

      Command help

    • 1.3.2 Start Nginx

      sudo nginx 或 sudo ./nginx
      

      Insert image description here
      Repeated startup will report an error that the port is already occupied.
      Insert image description here

    • 1.3.3 Stop Nginx and reload the configuration file: -s signal

      #停止有两个命令:
      sudo nginx -s stop 和 sudo nginx -s quit
      #区别是,stop是立即强制停止,而quit是会等工作线程完成已经在处理的所有请求后,才会停止。
      

      Insert image description here

      #在Nginx运行时修改了配置文件,需要刷新配置文件:
      sudo nginx -s reload
      

      Insert image description here

    • 1.3.4 Check the Nginx version and test the correctness of the configuration file: -s signal

      #查看版本有两个命令:
      sudo nginx -v 和 sudo nginx -V
      #命令的区别就是大写和小写,小写的输出信息比较简洁,大写的数据内容比较足(包含 编译器版本,配置参数)。
      sudo nginx -v
      

      Insert image description here

      #测试配置文件的语法正确性也有两个命令:(多用于修改完配置文件后测试修改的语法正确性)
      sudo nginx -t 和 sudo nginx -T
      #命令的区别也就是大写和小写,小写的输出信息比较简洁,大写的数据内容比较足(会把配置文件的内容用标准数据格式打印在控制台上)。
      

      Insert image description here


2. Use the system control command systemctl

We installed Nginx in the system. As an installed application, the operating system will also have some general control commands that can be used to operate it. However, the system's operation of it is definitely relatively simple, and there is definitely no command operation that comes with Nginx. many. But the advantage is that you can execute it anytime and anywhere without switching to the directory where the Nginx command execution file is located.

启动nginx服务:
sudo systemctl start nginx

停止nginx服务:
sudo systemctl stop nginx

重启nginx服务:
sudo systemctl restart nginx

重新加载nginx配置文件:
sudo systemctl reload nginx

查看nginx状态:
sudo systemctl status nginx

Example:
Insert image description here


3. Supplementally check the thread ID of Nginx and shut down Nginx by killing the thread.

#找对应pid有两种方法
1.使用命令 cat /var/run/nginx.pid
2.直接 ps -ax | grep nginx 找到master process(主线程)的Id
然后执行Linux的杀死线程命令:
sudo kill -s QUIT xxxx

Example:
Insert image description here

Guess you like

Origin blog.csdn.net/cjl836735455/article/details/131270234