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

來源:互聯網
上載者:User
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. nginx employs event-based model and OS-dependent 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 adjusted to the number of available CPU cores (see worker_processes).

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, or /usr/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啟動,關閉,重載設定檔的相關操作

Starting, Stopping, and Reloading Configuration

To start nginx, run the executable file. Once nginx is started, it can be controlled by invoking the executable with the -s parameter. Use the following syntax:

nginx -s signal

Where signal may be one of the following:

  • stop — fast shutdown
  • quit — graceful shutdown
  • reload — reloading the configuration file
  • reopen — reopening the log files

For example, to stop nginx processes with waiting for the worker processes to finish serving current requests, the following command can be executed:

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 is sent to nginx or it is restarted. To reload configuration, execute:

nginx -s reload

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 a success, the master process starts new worker processes and sends 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 accepting new connections and continue to service current requests until all such requests are serviced. After that, the old worker processes exit.


一旦啟動了nginx,就可以通過nginx -s [signal]命令的方式來控制nginx.其中[signal]可以為如下的命令:

  • stop — 快速停止
  • quit — 平滑關閉
  • reload — 重新載入設定檔
  • reopen — 重新開啟記錄檔
例如,等待worker進程處理完當前請求後再關閉nginx,可以使用

nginx -s quit

當設定檔被更改,只有當nginx被重啟或者接收到重載設定檔的命令時新的配置才會生效,為了更改設定檔後生效,可以使用

nginx -s reload

一旦master進程接收到重載設定檔的訊號,它首先會檢查新的設定檔是否有語法錯誤,如果沒有錯誤,master進程將會採用新的配置,並啟動新的worker進程,同時通知舊的worker進程讓他們停止工作。否則,若設定檔存在錯誤,那麼master進程仍然使用舊的配置,並且舊的worker進程將繼續保持工作。一旦master進程通知worker進程停止工作,worker進程首先會停止接收連結,然後處理完當前的所有請求,之後再exit,結束執行。

以上就介紹了nginx基本介紹(基於官方文檔),包括了方面的內容,希望對PHP教程有興趣的朋友有所協助。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.