Nginx installation

Yum info nginx View version

Yum install nginx - y installation

Nginx startup

Nginx - s stop

Nginx - s reload (reload takes effect after changing the configuration file)

Nginx - t Check syntax

performance optimization

1.worker_ processes number | auto

Number of worker processes; Usually, it should be the number of CPU cores

ps aux

2.worker_ cpu_ Affinity cpumask... (This option is not available in the default nginx. conf document and needs to be added manually)

worker_ cpu_ Affinity auto [apumask] improves cache hit ratio, which is conducive to faster CPU loading cache

Because the worker is bound to a fixed CPU core, it is more convenient for the worker to access the cache occupied by the CPU next time

Example: The server has a 4-core CPU, which is bound as:

00000001: CPU No. 0 First CPU

00000010: CPU 1 Second CPU

00000 100: CPU 2 The third CPU 0 is the starting CPU core, representing the first

00001000:3 CPU Fourth CPU

worker_ cpu_ Affinity 0001 0010 Bind two workers to two fixed CPU cores

If there are more CPUs, add the bindings in turn, such as three, four, five, and six

worker_ cpu_ affinity 00000001 00000010 00000100 00001000 00010000 00100000

Command to view the number of corresponding cpu cores

Ps axo pid, cmd, psr, nice | grep nginx View nginx process priority, pid process number, and cpu core number

Watch - n0.5 'ps axio pid, cmd, psr, nice | grep nginx' Grab the command executed above every 0.5 seconds and the results

  1. In the events option

worker_ connections 1024; The default upper limit of a work is 1024, which can be increased. RMB 20000

For worker_ connections 20000;

  1. Configure the format content to be filled in for a website. Edit the text location/etc/nginx/nginx Conf in the http module

option

server {

listen 80 default_ server; Website port default 80 Add default_ The server is set as the default page. If the default page is not added, it will be in order

listen [::]:80; The default value of ipv6 address is enough

server_ name _; Website domain name, fill in the format server_ name www.baidu.com;

root /usr/share/nginx/html; Website data storage directory

}

If there are multiple websites, continue to add the server option according to the above format

Or to/etc/nginx/conf. d/* Conf Edit a file with conf as the suffix to fill in the server content

Example:

Hide client query nginx version

Add a server in the http module_ tokens off;

Ha estat útil la resposta? 0 Els usuaris han Trobat Això Útil (0 Vots)