


Running and controlling Nginx - command line parameters and signals
Reference materials:
Nginx Chinese documentation:
Nginx start, stop, smooth restart, signal control and smooth upgrade:
Command line parameters:
Common commands:
-c filename: Set the configuration file.
-t: Do not run, but only test the configuration file. nginx will check the syntax of the configuration file for correctness and try to open the files referenced in the configuration file.
-s: Pass a signal, stop closes quickly, quit closes calmly, reopen reopens the log file, switches log files, and reloads the configuration file.
-v: Display the nginx version.
-V: Display nginx version, compiler version and configuration parameters
------------------------ -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ---
[root@localhost /]# alias nginx='/usr/local/nginx/sbin/nginx'<br>[root@localhost /]# alias

<br>
[root@localhost /]# nginx -h nginx version: nginx/1.11.13Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives] Options: -?,-h : this help -v : show version and exit -V : show version and configure options then exit -t : test configuration and exit -T : test configuration, dump it and exit -q : suppress non-error messages during configuration testing -s signal : send signal to a master process: stop, quit, reopen, reload -p prefix : set prefix path (default: /usr/local/nginx/) -c filename : set configuration file (default: conf/nginx.conf) -g directives : set global directives out of configuration file[root@localhost /]#
---------------------------------- -------------------------------------------------- -------------------------------------------------- ------------------------------------------
control signal :
You can use the signal system to control the main process. By default, nginx writes the pid of its main process to the /usr/local/nginx/logs/nginx.pid file. Change the location of this file by passing arguments to ./configure or using the pid command.
The main process can handle the following signals:
TERM,INT | Quick shutdown |
QUIT | Close gracefully |
HUP |
Reconfigure Start a new worker process with a new configuration Close the old worker process calmly |
USR1 | Reopen the log file, which is more useful when cutting logs |
USR2 | Smoothly upgrade the executable program |
WINCH | Close the worker process gracefully |
启动:
启动代码格式:nginx安装目录地址 -c nginx配置文件地址
[root@localhost ~]# alias nginx='/usr/local/nginx/sbin/nginx' [root@localhost ~]# nginx -c /usr/local/nginx/conf/nginx.conf [root@localhost ~]# ps -ef|grep nginx root 2073 1 0 10:37 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf nobody 2074 2073 0 10:37 ? 00:00:00 nginx: worker process root 2076 2022 0 10:37 pts/0 00:00:00 grep nginx [root@localhost ~]#
停止:
从容停止:
# ` 字符是数字键盘 1 字符左边的那个字符
[root@localhost ~]# kill -QUIT `cat /usr/local/nginx/logs/nginx.pid`
快速停止:
[root@localhost ~]# kill -TERM `cat /usr/local/nginx/logs/nginx.pid`
或
[root@localhost ~]# kill -INT `cat /usr/local/nginx/logs/nginx.pid`
强行停止:
[root@localhost ~]# kill -9 nginx
重启:
1.普通重启:关闭进程,修改配置后,重启进程
2.重新加载配置文件,不重启进程,不会停止处理请求
3.平滑更新nginx二进制,不会停止处理请求
=========================================================================
注意:在重载前,测试一下配置文件:
# -t 参数将检查配置文件的语法是否正确,默认会检查 /usr/local/nginx/conf/nginx.conf 文件
[root@localhost ~]# /usr/local/nginx/sbin/nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
# 如果要对指定配置文件进行语法检查,可以继续添加 -c 参数
[root@localhost ~]# /usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful [root@localhost ~]#
=========================================================================
nginx的平滑重启:
如果改变了nginx的配置文件,想重启nginx,同样可以发送系统型号给nginx主进程的方式来进行,重启之前,要确认配置文件是否正确
[root@localhost ~]# kill -HUP 【nginx主进程号】
当 nginx 接收到 HUP 信号时,它会尝试先解析配置文件,如果成功,就应用新的配置文件(例如,重新打开日志文件或监听的套接字)。之后,nginx 运行新的工作进程并从容关闭旧的工作进程。通知工作进程关闭监听套接字,但是继续为当前连接的客户提供服务。所有的客户端的服务完成后,旧的工作进程被关闭。如果新的配置文件应用失败,nginx 将继续使用旧的配置文件进行工作。
nginx的平滑升级:
当需要将正在运行中的nginx升级、添加/删除服务器模块时,可以在不中断服务的情况下,使用新的nginx可执行程序替换旧的:
1.使用新的可执行程序替换旧的可执行程序,对于编译安装的nginx,可以将新版本编译安装到nginx安装路径中,替换之前,备份一下旧的可执行文件
2.发送以下指令:
[root@localhost ~]# kill -USR2 【旧版本的nginx主进程号】
3.旧版本的nginx的主进程将重命名它的pid文件为.oldbin(例如:/usr/local/nginx/logs/nginx.pid.oldbin),然后执行新版本的nginx可执行程序,依次启动新的主进程和新的工作进程。
4.此时,新、旧版本的nginx实例会同时运行,共同处理输入的请求,要逐步停止旧版本的nginx,必须发送WINCH信号给旧的主进程,然后,它的工作进程就开始从容关闭:
[root@localhost ~]# kill -WINCH 【旧版本的nginx主进程号】
5.一段时间后,旧的工作进程(worker process)处理了所有已连接的请求后退出,仅由新的工作进程来处理输入的请求了。
6.这时候,可以决定是使用新版本,还是恢复到旧版了:
kill -HUP 【旧的主进程号】:nginx将在不重载配置文件的情况下启动它的工作进程
kill -QUIT 【新的主进程号】:从容关闭其工作进程(worker process)
kill -TERM 【新的主进程号】:强制退出
kill 【新的主进程号或旧的主进程号】:如果因为某些原因新的工作进程不能退出,则向其发送kill信号
新的主进程退出后,旧的主进程会移除.oldbin前缀,恢复为它的.pid文件,这样,一切就都恢复到升级之前了。
如果尝试升级成功,而你也希望保留新的服务器时,可发送QUIT信号给旧的主进程,使其退出而只留下新的服务器运行。
The above is the detailed content of Running and controlling Nginx - command line parameters and signals. For more information, please follow other related articles on the PHP Chinese website!

Linux maintenance mode is entered by adding init=/bin/bash or single parameters at startup. 1. Enter maintenance mode: Edit the GRUB menu and add startup parameters. 2. Remount the file system to read and write mode: mount-oremount,rw/. 3. Repair the file system: Use the fsck command, such as fsck/dev/sda1. 4. Back up the data and operate with caution to avoid data loss.

This article discusses how to improve Hadoop data processing efficiency on Debian systems. Optimization strategies cover hardware upgrades, operating system parameter adjustments, Hadoop configuration modifications, and the use of efficient algorithms and tools. 1. Hardware resource strengthening ensures that all nodes have consistent hardware configurations, especially paying attention to CPU, memory and network equipment performance. Choosing high-performance hardware components is essential to improve overall processing speed. 2. Operating system tunes file descriptors and network connections: Modify the /etc/security/limits.conf file to increase the upper limit of file descriptors and network connections allowed to be opened at the same time by the system. JVM parameter adjustment: Adjust in hadoop-env.sh file

This guide will guide you to learn how to use Syslog in Debian systems. Syslog is a key service in Linux systems for logging system and application log messages. It helps administrators monitor and analyze system activity to quickly identify and resolve problems. 1. Basic knowledge of Syslog The core functions of Syslog include: centrally collecting and managing log messages; supporting multiple log output formats and target locations (such as files or networks); providing real-time log viewing and filtering functions. 2. Install and configure Syslog (using Rsyslog) The Debian system uses Rsyslog by default. You can install it with the following command: sudoaptupdatesud

When choosing a Hadoop version suitable for Debian system, the following key factors need to be considered: 1. Stability and long-term support: For users who pursue stability and security, it is recommended to choose a Debian stable version, such as Debian11 (Bullseye). This version has been fully tested and has a support cycle of up to five years, which can ensure the stable operation of the system. 2. Package update speed: If you need to use the latest Hadoop features and features, you can consider Debian's unstable version (Sid). However, it should be noted that unstable versions may have compatibility issues and stability risks. 3. Community support and resources: Debian has huge community support, which can provide rich documentation and

This article describes how to use TigerVNC to share files on Debian systems. You need to install the TigerVNC server first and then configure it. 1. Install the TigerVNC server and open the terminal. Update the software package list: sudoaptupdate to install TigerVNC server: sudoaptinstalltigervnc-standalone-servertigervnc-common 2. Configure TigerVNC server to set VNC server password: vncpasswd Start VNC server: vncserver:1-localhostno

Configuring a Debian mail server's firewall is an important step in ensuring server security. The following are several commonly used firewall configuration methods, including the use of iptables and firewalld. Use iptables to configure firewall to install iptables (if not already installed): sudoapt-getupdatesudoapt-getinstalliptablesView current iptables rules: sudoiptables-L configuration

The steps to install an SSL certificate on the Debian mail server are as follows: 1. Install the OpenSSL toolkit First, make sure that the OpenSSL toolkit is already installed on your system. If not installed, you can use the following command to install: sudoapt-getupdatesudoapt-getinstallopenssl2. Generate private key and certificate request Next, use OpenSSL to generate a 2048-bit RSA private key and a certificate request (CSR): openss

Configuring a virtual host for mail servers on a Debian system usually involves installing and configuring mail server software (such as Postfix, Exim, etc.) rather than Apache HTTPServer, because Apache is mainly used for web server functions. The following are the basic steps for configuring a mail server virtual host: Install Postfix Mail Server Update System Package: sudoaptupdatesudoaptupgrade Install Postfix: sudoapt


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver CS6
Visual web development tools