nginx reload和reopen

nginx is stopped (nginx -s stop) or directly kill the process (kill -9 nginx process ID), the call command (nginx -s reload or nginx -s reopen) reports an error: Can not find "var / run / nginx .pid "file.

This sentence, there are several points of knowledge, but also contains some errors, mistakes have to reload or reopen as a command to start. In order to sum up:

1.nginx common commands

stop:

  • Nginx directly kill the process. ps aux | grep nginx nginx view of the main process ID, call kill -9 nginx process ID to forcibly stop nginx. (Also "kill -quit nginx process number" to calm stop nginx, "kill -term nginx process number" to quickly stop nginx)
  • Call nginx -s stop fast stop nginx
  • Call nginx -s quit stopping the complete and orderly nginx

start up: 

Nginx is installed into the directory / sbin / under execution

nginx nginx nginx.conf -c or specific location (usually the default is nginx -c ./logs/nginx.conf)

Restart:

nginx -s reload graceful restart. Configuration reload.

nginx work, including a master process, multiple worker processes. worker process is responsible for a specific http and other related work, master control, process control is mainly carried out. 

nginx -s reload command after modifying the configuration file is loaded, the following events occurred after the order was given

1. Check the correctness of the Nginx master process configuration file, an error message if an error is returned, nginx continue to use the original configuration file to work (because worker was unaffected)

2. Nginx start a new worker process using the new configuration file

3. Nginx will be assigned a new request for a new worker process

4. Nginx wait before worker process all the requests after the return has been close correlation worker process

5. Repeat the above process, knowing all the old worker processes are shut off.

So, after the restart, master of the same process ID, process ID will change the worker's.

Log division:   

nginx -s reopen reopen the log file.

Why cut the log? Some people will open after logging installed Nginx general, some people will turn off logging, turn on logging of people usually erected on the Nginx web logs of all there is the same file (for example, I exist log file access.log in),

Over time this site will record all access to the log files pile up much bigger when you need to view the log file when a look at the long list, is not convenient to find. Now, if I put daily log files to identify separated out with a date so much easier to find a.

My suggestion is to turn on logging, logging which kept a lot of useful things. For example: the name of the browser, you can easily make adjustments to the layout of the site; IP address, if the site receives attack, you can be found on that IP address.

Under Linux we can simply go to the log file mv, mv gone but you will find a new log file does not regenerate, file handles for General linux, the file is opened you go mv file the case, but the original operating this document the process still has the file inode information,

The original process still read the original file, so a simple mv is not in force.

Therefore, the recommended procedure is as follows

1. mv original file to a new file in the directory, this time nginx also wrote this document (written to the new location in the file)

2. Call nginx -s reopen to open the log file, which will nginx new log information is written to the new file

This completes the cutting work logs, and the cutting process is not lost logs.

The current test configuration file is correct: nginx -t

Tests if the specified configuration file is correct: nginx -t specify the configuration file path

2.var / run / nginx.pid file

First var / run directory is doing with this?

This folder contains system information data describing the system since the start. This file folder must be removed early in the boot process (delete or zero). Program can /var/runhave its own sub-folder. Originally placed /etcunder the process ID (PID) file must be placed

In the /var/runinside. PID file naming convention is <program-name>.pid. So, nginx's PID file named /var/run/nginx.pid.

nginx.pid storage is the process number of nginx's master process.

3. Why will complain

When nginx is stopped, var / run / nginx.pid been deleted. And reopen and reload commands need to get through nginx.pid process ID, you will find var / run.nginx.pid, if not, on the error.

4. Summary

reopen in the case of nginx started to make use of split logs, reload but also in the case of nginx started to make a smooth restart, they are dependent on the presence of nginx process. Not literally start or turn on meaning.

The real start command is: Profile nginx.conf nginx nginx -c or specified directory. View the process signifies the presence of a successful start, after the call to reload again and would not reopen the error.

nginx: [error] open() “/usr/local/nginx/logs/nginx.pid” failed (2: No such file or directory) 
[root@VM_16_6_centos sbin]# ./nginx -c /usr/local/nginx/conf/nginx.conf

Guess you like

Origin www.cnblogs.com/zhuyeshen/p/12061458.html