[Nginx] Nginx core file structure analysis

1 Nginx core configuration structure

Insert picture description here

2 Detailed explanation of configuration module

  1. Set the user of the worker process, which refers to the user in linux, which will involve some permissions for nginx to manipulate directories or files. The default is nobody
user root;
  1. Set the number of worker processes. Generally speaking, if there are a few CPUs, just set a few, or set it to N-1.
worker_processes 1;
  1. nginx log level debug | info | notice | warn | error | crit | alert | emerg, the error level increases from left to right

  2. Set nginx process pid

pid        logs/nginx.pid;
  1. Set working mode
events {
    # 默认使用epoll
    use epoll;
    # 每个worker允许连接的客户端最大连接数
    worker_connections  10240;
}
  1. http is a command block, some command configuration for http network transmission
http {
}
  1. include introduces external configuration to improve readability and avoid a single configuration file from being too large. For example, when there are too many virtual host servers, all server modules can be mentioned in a separate configuration file.
include       mime.types;
  1. Set the log format, main is the defined format name, so access_log can directly use this variable
    Insert picture description here

Parameter name parameter meaning

$remote_addr	客户端ip
$remote_user	远程客户端用户名,一般为:’-’
$time_local	时间和时区
$request	请求的url以及method
$status	响应状态码
$body_bytes_send	响应客户端内容字节数
$http_referer	记录用户从哪个链接跳转过来的
$http_user_agent	用户所使用的代理,一般来时都是浏览器
$http_x_forwarded_for	通过代理服务器来记录客户端的ip
  1. sendfile uses efficient file transmission to improve transmission performance. Tcp_nopush can only be used after it is enabled, which means that the data packets are sent only after they have accumulated a certain size, which improves efficiency.
sendfile        on;
tcp_nopush      on;
  1. keepalive_timeout sets the timeout period between client and server requests to ensure that new connections will not be repeatedly established when the client requests multiple times, saving resource consumption. In seconds. Set to 0, which means that each request establishes a new connection.
#keepalive_timeout  0;
keepalive_timeout  65;
  1. Enable compression, the transmission of html/js/css will be faster after compression
gzip on;
  1. server can set multiple virtual hosts in the http command block
  • listen port
  • server_name localhost, ip, domain name
  • location request routing mapping, matching interception
  • root request location
  • index homepage settings
server {
	listen       88;
	server_name  localhost;
	location / {
		root   html;
		index  index.html index.htm;
	}
}

Guess you like

Origin blog.csdn.net/LIZHONGPING00/article/details/112393778