Nginx study notes - start and stop

WBOY
Release: 2016-07-29 08:56:57
Original
1109 people have browsed it

To start

just run the nginx executable file directly.

<code>[gap<span>@localhost</span> sbin]$ <span>pwd</span>
/usr/local/nginx/sbin

[gap<span>@localhost</span> sbin]$ ll
total <span>3208</span>
-rwxr-xr-x <span>1</span> root root <span>3283671</span> Jan <span>26</span><span>21</span>:<span>47</span> nginx
<span>//启动nginx</span>
[gap<span>@localhost</span> sbin]$ sudo ./nginx 
<span>//查看nginx进程</span>
[gap<span>@localhost</span> sbin]$ ps -ef|grep nginx
root     <span>30225</span><span>3727</span><span>0</span><span>22</span>:<span>44</span> pts/<span>0</span><span>00</span>:<span>00</span>:<span>00</span> sudo ./nginx
root     <span>32497</span><span>1</span><span>0</span><span>23</span>:<span>20</span> ?        <span>00</span>:<span>00</span>:<span>00</span> nginx: master process ./nginx
nobody   <span>32499</span><span>32497</span><span>0</span><span>23</span>:<span>20</span> ?        <span>00</span>:<span>00</span>:<span>00</span> nginx: worker process
gap      <span>32504</span><span>3727</span><span>0</span><span>23</span>:<span>20</span> pts/<span>0</span><span>00</span>:<span>00</span>:<span>00</span> grep --<span>color</span>=auto nginx</code>
Copy after login

Control

Once nginx is started, the program can be controlled using the -s parameter when calling the executable file. Use the following syntax:

<code> nginx <span>-s</span> signal</code>
Copy after login

where signal can be the following value:

<code><span>stop</span> — 快速关闭
quit — 优雅地关闭
reload — 重新家在配置文件
reopen — 重新打开日志文件</code>
Copy after login

stop

For example, if you want to wait for the worker process to process 10,000 current requests before exiting nginx, you can use the following command:

<code>nginx <span>-s</span> quit</code>
Copy after login

You must use startup The nginx user executes this command.

Reload the configuration file

After modifying the configuration file, it will only take effect if the reload command is passed to the nginx process or nginx is restarted.
Restart nginx:

<code>nginx <span>-s</span> reload</code>
Copy after login

Once the main process receives the signal to reload the configuration, it checks the syntax correctness of the new configuration file and attempts to apply the configuration information. If successful, the main process will start a new worker process and send a message to the old worker processes, asking them to shut down; otherwise, the main process rolls back the modifications and continues to use the old configuration. When the old worker process receives the shutdown command, it stops accepting new connections and continues to process current requests until all requests are processed, and then the old worker process exits.

Other control methods

With the help of Unix tools (such as the kill tool), signals can also be sent to the nginx process. In this case, the signal is sent directly to the process with the specified ID. The ID of the nginx main process is written in the nginx.pid file by default, which is saved in the /usr/local/nginx/logs directory, or in the /var/run directory. For example, if the main process ID
At 1628, send the QUIT signal to let nginx exit gracefully, execute:

<code>kill <span>-s</span> QUIT <span>1628</span></code>
Copy after login

To get the running nginx process, use the ps tool, for example:

<code>ps -ax <span>| grep nginx</span></code>
Copy after login

To learn more about sending signals to nginx, you can refer to the official documentation Controlling nginx part.

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces the Nginx learning notes - starting and stopping, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!