首頁  >  文章  >  後端開發  >  nginx基本介紹(基於官方文件)

nginx基本介紹(基於官方文件)

WBOY
WBOY原創
2016-08-08 09:20:12907瀏覽

nginx has one master process and several worker processes. The main purpose of the master process is to read and evaluate configuration, and maintain worker processes. Worker processes do actual processing of requests. nginxemploys eventer mechanisms to efficiently distribute requests among worker processes. The number of worker processes is defined in the configuration file and may be fixed for a given configuration or automatically.

The way nginx and its modules work is determined in the configuration file. By default, the configuration file is named nginx.conf and placed in the directory /usr/local/nginx/conf, /etc/nginx, local. /etc/nginx.

nginx由一個master進程和若干worker進程組成,master進程主要用於讀取設定檔和管理worker進程.worker進程負責處理請求。 nginx基於事件模型並且能夠根據作業系統的特性高效的利用worker進程處理請求。 worker進程的數量在設定檔中定義,也可以透過指定的設定檔來定義其數量,或自動根據CPU核心數來確定其數量。
nginx以及相關模組的工作方式是透過設定檔來指定。預設情況下,設定檔命名為nginx.conf,位於/usr/local/nginx/conf 或 /etc/nginx 或 /usr/local/etc/nginx 路徑下。

以下內容為nginx啟動,關the executable with the 

-s
 parameter. Use the following syntax:

nginx -s <em>signal</em>

Where signal may be 38 the folloWhere 

signal
 
quit

 — graceful shutdown

reload
     — reloading the configuration file
  • reopen
  •  — reopening the log files
  • For example, to stop nginx process with procesd ed:
  • nginx -s quit
    
    This command should be executed under the same user that started nginx.
  • Changes made in the configuration file will not be applied until the command to reload configuration file will not be applied until the command to reload configuration isload p膜 <pre class="brush:php;toolbar:false">nginx -s reload </pre>
  • Once the master process receives the signal to reload configuration, it checks the syntax validity of the new configuration file and tries to apply the configuration provided in it. If this is 5, the apply the configuration provided in it. If this is messages to old worker processes, requesting them to shut down. Otherwise, the master process rolls back the changes and continues to work with the old configuration. Old worker processes, receiving a command to shut down, stop cepting new. continue to service current requests until all such requests are serviced. After that, the old worker processes exit.

一旦啟動了nginx,就可以透過其中nginx -s [signal]命令的方式來控制其中包括signalinx.可以以下的指令:

stop
 — 快速停止

quit

  — 重新開啟日誌檔案

例如,等待worker進程處理完目前請求後再關閉nginx,可以使用

  • nginx -s quit
  • 當配置文件被更改,只有當nginx被重啟或接收到重載配置文件的命令時新的配置文件才會生效,為了更改配置文件後生效,可以使用



nginx -s reload

一旦master程序接收到重載配置文件的信號,它首先會檢查新的配置文件是否有語法錯誤,如果沒有錯誤,master進程將會採用新的配置,並啟動新的worker進程,同時通知舊的worker進程讓他們停止工作。否則,若設定檔存在錯誤,那麼master進程仍然使用舊的配置,並且舊的worker進程將繼續保持工作。一旦master進程通知worker進程停止工作,worker進程首先會停止接收鏈接,然後處理完當前的所有請求,之後再exit,結束執行。 🎜🎜🎜 🎜 以上就介紹了nginx基本介紹(基於官方文件),包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。 🎜 🎜 🎜
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn