Configuration and debugging of lightweight HTTP server Nginx

Source: Internet
Author: User
Tags epoll

Nginx installation is complete, the corresponding installation directory will be generated, according to the previous installation path, Nginx's profile path is/opt/nginx/conf, where nginx.conf is the nginx main configuration file. Here is the key to nginx.conf this configuration file.

The Nginx configuration file is divided into four parts: main (Global Settings), Server (host settings), upstream (Load Balancing server settings), and location (URL matches settings at a specific location). The instructions that are set in the main section affect all other settings, and the instructions in the server section are used primarily to specify the host and port; the upstream directives are used primarily for load balancing, setting up a series of back-end servers, and location parts to match the page location. The relationship between the four: server Inherits Main,location inheritance Server,upstream does not inherit other settings and is not inherited.

In each of these four sections, each section contains instructions that mainly contain Nginx main module directives, Event module directives, HTTP Core module directives, and other HTTP module directives for each section, such as HTTP SSL modules, Httpgzip static modules and HTTP addition modules.

The following is a Nginx configuration instance that details the meaning of each instruction under nginx.conf. To get a clearer idea of the structure of the nginx and the meaning of each configuration option, here is a nginx configuration file divided into 7 sections, followed by a description of the 7 sections below.

Global configuration for 1.Nginx

The following section is a global property configuration for Nginx, as follows:

User nobody nobody;

Worker_processes 4;

Error_log Logs/error.log Notice;

PID Logs/nginx.pid;

Worker_rlimit_nofile 65535;

events{

Use Epoll;

Worker_connections 65536;

}

The meaning of each configuration option in the above code is explained as follows:

User is a master module directive that specifies that the Nginx worker process runs the user and the user group, which is run by default by the nobody account.

Worker_processes is a main module directive that specifies the number of processes to open nginx. Each nginx process consumes 10m~12m memory on average. According to experience, generally specify a process enough, if it is a multi-core CPU, it is recommended to specify the number of processes as the CPU can be.

Error_log is a master module directive that defines a global error log file. The log output level has debug, info, notice, warn, error, crit to choose from, where the debug output log is the most detailed, and the Crit output log is the least.

The PID is a main module directive that specifies the location of the stored file for the process ID.

Worker_rlimit_nofile is used to specify the maximum number of file descriptors that a nginx process can open, which is 65535, and needs to be set using the command "Ulimit-n 65535".

The events directive is to set the Nginx working mode and the maximum number of connections.

events{

Use Epoll;

Worker_connections 65536;

}

Use is an event module directive that specifies the working mode of the Nginx. The working modes supported by Nginx are SELECT, poll, Kqueue, Epoll, Rtsig, and/dev/poll. Select and poll are standard working modes, kqueue and epoll are efficient working modes, and Epoll are used on Linux platforms, while Kqueue are used in BSD systems. For Linux systems, the Epoll mode of work is preferred.

Worker_connections is also an event module directive that defines the maximum number of connections per process Nginx, which defaults to 1024. The maximum number of client connections is determined by the worker_processes and Worker_connections, that is, max_ Client=worker_processes*worker_connections, when acting as a reverse proxy, the max_clients becomes: max_clients = worker_processes * Worker_ Connections/4.

The maximum number of connections to a process is limited by the maximum number of open files for the Linux system process, and the Worker_connections settings will not take effect until the operating system command "Ulimit-n 65536" is executed.

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.