nginx-conf

nginx最小配置解析,以及与业务场景对应关系。

Nginx多进程模型

Nginx最小配置解析

/etc/nginx/nginx.conf

worker_processes

nginx可以使用多个worker进程,原因如下:

to use SMP
to decrease latency when workers blockend on disk I/O
to limit number of connections per process when select()/poll() is used

一个CPU内核对应一个worker_process

http=>mime.types

浏览器是如何知道一个文件是要被下载还是要被展示?
通过加载另一个配置文件实现

sendfile on

数据零拷贝,既减少了中间调度,又减少了复制的过程
nginx应用程序内存不去加载磁盘上的文件,直接让数据发送给网络接口缓存

keepalive_timeout

保持连接超时的时间

虚拟主机(vhost)

server{
listen
server_name localhost;
location / {
# 域名后边跟的子目录/路径 URI
}

error_page 500 502 503 504 ……
# 访问出错时重定向到对应页面
location = /50x.html{
    root html;
}

}

域名解析与泛域名解析

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
worker_connections 768;
# multi_accept on;
}

http {

##
# Basic Settings
##

sendfile on;
tcp_nopush on;
types_hash_max_size 2048;
# server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# SSL Settings
##

ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;

# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}


nginx-conf
https://43.242.201.154/2025/07/13/nginx-conf/
Author
Dong
Posted on
July 13, 2025
Licensed under