Nginx 配置文件

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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx; 设置用户与组
worker_processes auto; 启动子进程数
error_log /var/log/nginx/error.log; 错误日志文件及日志级别
pid /run/nginx.pid; 进程号保存文件

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
worker_connections 1024; 每个进程可以处理的连接数,受系统文件句柄的限制
}

http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 使用 log_format 可以自定义日志格式,名称为 main
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main; 创建访问日志,格式采用 main 定义的格式

sendfile on; 是否调用 sendfile() 进行数据复制,sendfile() 复制数据是在内核级别完成的,所以会比一般的 read,write 更高效
tcp_nopush on; 开启后服务器的响应头部信息产生独立的数据包发送,即一个响应头信息一个包
tcp_nodelay on;
keepalive_timeout 65; 保持连接的超时时间
types_hash_max_size 2048;
gzip on; 是否采用压缩功能,将页面压缩后更节省流量

include /etc/nginx/mime.types; mime.types 为文件类型定义文件
default_type application/octet-stream; 默认文件类型

# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;

server {
listen 80 default_server; 服务器监听的端口
listen [::]:80 default_server;
server_name _; 访问的域名
root /usr/share/nginx/html; 设置网页根路径

# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;

location / {
root html;
index index.html index.htm; 首页文件,先找 index.html,若没有,再找 index.htm
}

error_page 404 /404.html; 设置错误代码对应的错误页面
location = /40x.html {
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}

# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server; 监听 TLS 使用的 443 端口
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt"; 指定证书文件,使用相对路径证书需要放在与 nginx.conf 同目录下
# ssl_certificate_key "/etc/pki/nginx/private/server.key"; 指定私钥文件,使用相对路径证书需要放在 nginx.conf 同目录下
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }

}