Nginx Beginner's Guide (beginner's article)

Source: Internet
Author: User

Reference Nginx Official documentation


This article will introduce some basic and common nginx commands and combine Examples of official website for a brief explanation , suitable for beginners to read. and assume that the reader has been installed on the server to deploy the Nginx service (installation deployment please refer to: Nginx installation Deployment introduction), Higher advanced users please go out to the right.

This guide will explain the Nginx configuration file structure from how to start, stop Nginx service and how to reload Nginx configuration as a pointcut. It also describes how to set nginx static content service, dynamic Proxy service and connect to Public Gateway Interface (FastCGI).


Common basic commands

The ability to master basic operational commands can reduce the amount of wasted time (although this is a far-fetched statement for these basic commands)

Start Command

Windows operating system environment (on the DOS command board, into the directory where nginx is executed),

> Start Nginx or Nginx.exe

Linux operating system environment (just for example, the exact path is the actual),

$/usr/local/nginx/sbin/nginx-c/usr/local/nginx/conf/nginx.conf


Invoke control command

For starting or running the executable file, once the Nginx boot, you can call the-s + parameters in the form of control, the specific nginx command format, as follows:

$ nginx-s Signal

The signal instance, as shown below

    • stop-Fast Stop Nginx service

    • quit-Graceful Stop Nginx service (waits for service to stop after the current service process has finished running)

    • reload-Reload the Nginx policy configuration file and restart

    • reopen-reopening the log files

For example, to stop the Nginx service after the Nginx service response completes the current request, you should use the following command:

$ nginx-s Quit

Note: The execution of these commands requires the user to complete the operation under the current Nginx service;


The following focus on the nginx-s reload command execution, what is the internal working mechanism of Nginx service?

first , when the Nginx service master process receives a reload and reboot command, Nginx will first check that the changed configuration syntax is correct, and try to follow the new configuration parameters;

If everything is OK, then the Nginx service master process restarts a service worker process and sends a message to notify the old service worker process to close the old process.

Additionally , the main process rolls back and continues to work with the old configuration, and after the old worker process receives the stop work message, it starts rejecting all new connection requests and continues processing the received request until all the requested services have been completed.

finally , the old service worker process exits the entire service and destroys it.


Other orders of the egg

Kill the specified process of the Nginx service:

Kiss-s QUIT 1628

Note: 1628 is a process ID of Nginx

Get the process for all activities of Nginx service:

Ps-ax | grep nginx

Click to view more Nginx service commands


Nginx configuration file Structure

Nginx is composed of several modules in a configuration file that are packaged in a specified set of instructions. Instruction groups can be split into multiple simple instructions or instruction blocks. A simple instruction is composed of the parameter name, the middle space of the parameter value, and the semicolon at the end. An instruction block structure is similar to a simple instruction structure, but is enclosed in the form of curly braces (' {} '). If an instruction block contains an additional set of instructions, it can be similar to events, HTTP, server, and so on, as the Nginx default configuration.


The pound sign (' # ') is the identifier used for the comment line.


(not to be continued)


Nginx Beginner's Guide (beginner's article)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.