The Nginx configuration file is a plain text file, and the entire configuration file is organized as a block. Main, events, HTTP, server, location. You can include multiple server modules in an HTTP module, and you can also include multiple location modules in one server module. The following is an example configuration file for Nginx.
#定义Nginx运行的用户和用户组
User nobody;
#nginx进程数, the recommended setting is equal to the total CPU core number
Worker_processes 1;
#进程文件
PID Nginx.pid;
#全局错误日志定义类型, [Debug | info | notice | warn | error | crit]
Error_log Logs/error.log Notice;
#一个nginx进程打开的最多文件描述符数目, the theoretical value should be the number of open files (the value of the system ulimit-n) and the number of nginx processes, but the Nginx allocation request is not uniform, so the recommendation is consistent with the value of ulimit-n.
Worker_rlimit_nofile 65535;
#工作模式与连接数上限
Events {
#参考事件模型, use [kqueue | rtsig | epoll |/dev/poll | select | poll]; The Epoll model is a high-performance network I/O model in the Linux version 2.6 kernel, and if it runs on FreeBSD, it uses the Kqueue model.
Worker_connections 65535;
#单个进程最大连接数 (maximum number of connections = number of connections * processes)
Use Epoll;
}
#设定http服务器
HTTP {
Include Mime.types; #文件扩展名与文件类型映射表
Default_type Application/octet-stream; #默认文件类型
#日志记录格式
Log_format Main ' $remote _addr-$remote _user [$time _local] '
"$request" $status $bytes _sent '
' "$http _referer" "$http _user_agent" '
' $gzip _ratio ';
Log_format Download ' $remote _addr-$remote _user [$time _local] '
"$request" $status $bytes _sent '
' "$http _referer" "$http _user_agent" '
' "$http _range" "$sent _http_content_range";
#日志名称, and the logging format takes the main
Access_log Logs/access.log Main;
#允许客户端请求的最大单文件字节数.
Client_max_body_size20M;
#该指令用于设置客户端请求的Header头缓冲区大小, the default value is 4KB.
Client_header_buffer_size 4k;
#设置用于读取大客户机请求头文件的最大数量和大小.
Large_client_header_buffers 4 8k;
Client_header_timeout 10; #指定客户端请求头读取超时时间.
Client_body_timeout 10; #指定客户端请求主体读取超时时间.
Send_timeout 10; #指定响应客户端的超时时间.
#开启高效文件传输模式, the sendfile instruction specifies whether Nginx calls the Sendfile function to output the file, and for normal applications to be set to ON, if it is used for downloading applications such as disk IO heavy load applications, can be off to balance disk and network I/O processing speed, Reduce the load on the system.
Sendfile on;
Tcp_nopush on; #防止网络阻塞
Tcp_nodelay on; #防止网络阻塞
Keepalive_timeout 60; #长连接超时时间, the unit is seconds.
gzip on; #开启gzip压缩输出.
Gzip_min_length 1k; #最小压缩文件大小.
Gzip_http_version 1.1; #压缩版本.
Gzip_buffers 4 8k; #压缩缓冲区.
Gzip_comp_level 2; #压缩等级.
#压缩类型, the default is already included text/html, so there is no need to write, write up will not have a problem, but there will be a warn.
Gzip_types text/plain application/x-javascript text/css application/xml;
Gzip_vary on; #如果指令gzip, gzip_static, or gunzip active, enable the Insert Vary:accept-encoding response header field.
#定义虚拟主机开始的关键字.
server {
Listen 80; #指定虚拟机的服务端口.
server_name www.jason1.com; #用来指定ip地址或者域名.
Access_log Logs/host.access.log Main; #设置虚拟主机的访问日志存放路径, main specifies the log output format.
Server_name_in_redirect off;
Location/{
Index index.html; #指定访问的默认首页.
Root/usr/local/nginx/html/jason1; #设置虚拟机的网页个目录, the directory can be either an absolute path or a relative directory.
}
Error_page 404 /404.html; #指定各种错误返回页面.
Error_page 502 503 504/50x.html;
Location =/50x.html {
root/usr/local/nginx/html;
}
Location/status {
Stub_status on; A #设置为on that represents the work status statistics feature of the startup Stubstatus (prior to 1.7.5, this parameter must specify the parameter on.) 1.7.5 after the version only needs to specify Stub_status).
Access_log/usr/local/nginx/logs/status.log; #用来指定stubstatus模块的访问日志.
Auth_basic "Nginxstatus"; #开启使用 the user name Password authentication for the HTTP Basic authentication protocol. The specified parameter is used as the domain. The parameter off can de-inherit the effect from the previous configuration level auth_basic directive.
AUTH_BASIC_USER_FILE/USR/LOCAL/NGINX/CONF/HTPASSWD;} #指定认证的密码文件.
Location ~/\.ht {
Deny all;
}
}
}
This article is from "Technical achievement dream!" "Blog, be sure to keep this provenance http://dreamsanqin.blog.51cto.com/845412/1714694
Nginx configuration file Parameters detailed