Table of Contents
1: main parameters
1.1 worker_processes
1.2 worker_cpu_affinity
1.3 worker_priority
1.4 worker_rlimit_nofile
1.5 error_log
1.6 pid
1.7 user
2: Events parameters
2.1 worker_connections
2.2 accept_mutex
2.2.1 Jingqun Phenomenon
2.2.2 accept lock processing
2.2.3 Disadvantages of accept lock
2.2.4 Configuration suggestions
2.3 accept_mutex_delay
Home Operation and Maintenance Nginx Introduction to parameters that must be configured in nginx

Introduction to parameters that must be configured in nginx

Nov 12, 2020 pm 04:00 PM
nginx parameter

Introduction to parameters that must be configured in nginx

1: main parameters

1.1 worker_processes

# 指定nginx开启worker工作子进程数量# number默认1,建议配置数量与CPU核心数量相等worker_processes number复制代码
Copy after login

1.2 worker_cpu_affinity

# nginx默认未开启利用多核CPU,开启某个核心该位置标志为1即可# worker_processes 最多开启8个,所以多核最多8个也就够用。示例配置开启4核worker_cpu_affinity 00000001 00000010 00000100 00001000复制代码
Copy after login

1.3 worker_priority

# 进程优先级,数值越低占用资源越多# number默认10,值范围-20 ~ 20# 建议配置-10即可,最好别低于Linux系统进程-5优先级worker_priority number复制代码
Copy after login

1.4 worker_rlimit_nofile

# 一个子进程可以打开文件描述限制# nginx默认一个子进程打开文件描述限制数量 = (ulimt -u) / worker_processes# 因为进程处理连接任务很多时候不均衡,所以最好设置为与系统数量一致worker_rlimit_nofile (ulimit -u)复制代码
Copy after login

1.5 error_log

# file指定日志输出文件位置,默认logs/error.log# level指定日志输出最低级别,默认error级别。当然可以设置为debug、info等error_log file [level]复制代码
Copy after login

1.6 pid

# file默认值logs/pid.log,指定nginx中master进程的PID输出文件位置pid file复制代码
Copy after login

1.7 user

# user第二个参数user,配置nginx进程运行用户,默认nobody# group配置nginx进程运行用户组,默认nobodyuser user [group]复制代码
Copy after login

2: Events parameters

2.1 worker_connections

# nginx指定一个子进程可处理连接数量# number默认数量1024# nginx可处理连接总数 = worker_processes * worker_connecitonsworker_connections  number复制代码
Copy after login

2.2 accept_mutex

The accept_mutex parameter is the accept mutex lock switch for the worker process to process the connection. The default is on before 1.11.3, and the default is off in later versions

2.2.1 Jingqun Phenomenon

Nginx can configure multiple worker processes through the worker_processes parameter. Multiple worker processes will listen to the same port after forking. If an external connection comes in, all child processes will be awakened to seize the connection. Unless one child process successfully handles the accept event, the child processes will go back to sleep. Resulting in many unnecessary context switches. This is the thundering herd phenomenon

2.2.2 accept lock processing

nginx adds an accept mutex so that there is only one process registered in epoll, thereby avoiding the thundering herd phenomenon. That is to say, when a connection comes in, there can only be one child process to handle it

尝试获取accept锁if success
    在epoll中注册accept事件else
    在epoll中注销accept事件
处理所有连接事件
释放accept锁复制代码
Copy after login
2.2.3 Disadvantages of accept lock

The accept lock seems to perfectly solve the problems caused by the thundering group phenomenon, but it also brings The problem arises that some child processes are very busy and some child processes are very idle, especially in applications with relatively high throughput and concurrency. Generally speaking, it is the problem of uneven load of worker sub-processes

2.2.4 Configuration suggestions
  • For distributed application short connections, it is best to turn on this parameter to avoid too many The context switching overhead
  • For long-connection applications, it is best to turn off this parameter to avoid excessive connection load on a worker and causing high CPU utilization of a process

2.3 accept_mutex_delay

When accept_mutex is set to on, you need to debug the accept_mutex_delay parameter according to the application scenario. This parameter specifies the time after which all child processes will re-rob the accept lock. Appropriate parameter values ​​can help reduce worker load imbalance problems. Default value 500ms

Related recommendations:nginx tutorial

The above is the detailed content of Introduction to parameters that must be configured in nginx. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to configure nginx in Windows How to configure nginx in Windows Apr 14, 2025 pm 12:57 PM

How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.

How to check the name of the docker container How to check the name of the docker container Apr 15, 2025 pm 12:21 PM

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

How to check whether nginx is started How to check whether nginx is started Apr 14, 2025 pm 01:03 PM

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

How to start containers by docker How to start containers by docker Apr 15, 2025 pm 12:27 PM

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".

How to check nginx version How to check nginx version Apr 14, 2025 am 11:57 AM

The methods that can query the Nginx version are: use the nginx -v command; view the version directive in the nginx.conf file; open the Nginx error page and view the page title.

How to create containers for docker How to create containers for docker Apr 15, 2025 pm 12:18 PM

Create a container in Docker: 1. Pull the image: docker pull [mirror name] 2. Create a container: docker run [Options] [mirror name] [Command] 3. Start the container: docker start [Container name]

How to configure cloud server domain name in nginx How to configure cloud server domain name in nginx Apr 14, 2025 pm 12:18 PM

How to configure an Nginx domain name on a cloud server: Create an A record pointing to the public IP address of the cloud server. Add virtual host blocks in the Nginx configuration file, specifying the listening port, domain name, and website root directory. Restart Nginx to apply the changes. Access the domain name test configuration. Other notes: Install the SSL certificate to enable HTTPS, ensure that the firewall allows port 80 traffic, and wait for DNS resolution to take effect.

How to start nginx server How to start nginx server Apr 14, 2025 pm 12:27 PM

Starting an Nginx server requires different steps according to different operating systems: Linux/Unix system: Install the Nginx package (for example, using apt-get or yum). Use systemctl to start an Nginx service (for example, sudo systemctl start nginx). Windows system: Download and install Windows binary files. Start Nginx using the nginx.exe executable (for example, nginx.exe -c conf\nginx.conf). No matter which operating system you use, you can access the server IP

See all articles