[Translation] nginx Beginner's Guide

nginx Beginner's Guide

This translation from nginx official website: http: //nginx.org/en/docs/beginners_guide.html#control

The guide will give a brief introduction to nginx, and nginx describe the use of some simple tasks done. This guide assumes that the reader of the machine has been installed nginx. If not installed, move to Installing nginx page to complete the installation. This guide describes how to start and stop nginx, how to reload nginx configuration, explain the composition of configuration files and how to use nginx deliver static resources, how to configure nginx as a proxy server, and how to connect to the FastCGI nginx .

nginx has a master process and several workers processes. The main work of the main process is the value read and evaluate the configuration file, while maintaining worker process. Worker process to handle the actual request. nginx using event-based model and operating system-independent mechanism to efficiently distribute requests among the working process. Number of work processes is defined in the configuration file, can be fixed for a given configuration, can be automatically adjusted according to the number of available CPU cores (see worker_processes ).

nginx and determines how the module in the configuration file. By default, the profile name nginx.conf, and placed in the / usr / local / nginx / conf, / etc / nginx or / usr / local / etc / nginx. Directory.

Start, stop and reload nginx configuration files

To start nginx, running nginx executable file. Once nginx started, you can configure it via the command line arguments of calling -s. Use the syntax:

nginx -s signal

it may be a signal listed:

  • stop - Fast Close
  • quit - Elegant Close
  • reload - reload the configuration file
  • reopen - Reopen the log file

For example, to stop the process nginx, waiting for service worker process to complete the current request, you can execute the following command:

nginx -s quit

Note: This command should be executed under the same user nginx's start.

Before being sent to nginx or re-boot configuration in order to reload the configuration will not apply the changes made to the configuration file. To reload the configuration, execute:

nginx -s reload

Once the main process receives a signal to reload the configuration file, it first checks the syntax of the configuration file is valid, and then try to configure the application configuration file provided. If successful, he will create a new worker process, and sends a message to the old worker process to inform the old worker process shut down. Otherwise, the main thread rollback configure and use the old configuration. At the same time the old worker process receives a request to shut down, to stop receiving and processing after the current request is connected to know the current request is completed, the old workers to shut down and exit.

With the help of some tools / commands you may also want to send a signal nginx, such as kill. In the present embodiment, a signal is sent directly to the process having a process ID given. By default, the process ID is written to the main process nginx nginx. PID, which is located in / usr / local / nginx / logs or / var / run directory. For example, if the primary process ID is 1628, to send a signal to exit gracefully shut down resulting in nginx (quit command), execute:

kill -s QUIT 1628

To get a list of all running nginx process, you can use ps tools, such as:

ps -ax | grep nginx

For more information about sending a signal to nginx, see: Controlling nginx .

Configuration file structure

nginx is composed of modules, and the module configuration file control instruction. Instruction blocks into instructions and simple instructions. Executed by a simple name and parameters, which are separated by a space, and a semicolon (;) end. Instruction block having the same structure as the simple instructions, but it does not end with a semicolon, but a set of braces ({and}) surrounded by additional instructions. If a block of instructions in the instruction can include other braces, then it is called a context (e.g.: Events , HTTP , Server , and LOCATION )

In a configuration file outside the context of any instruction it is considered the main context. http events and instructions resident in the main context, server resides in the http, location resides on the server.

In #as comments behind the number will be.

Serving static content

Home to write it, which got off work

Guess you like

Origin www.cnblogs.com/pangjianxin/p/10969379.html