[root@nginx ~]# cat nginx.conf
user www; #nginx用户
worker_processes auto; #自动根据CPU核心数启动worker数量
worker_cpu_affinity auto; #开启亲和性
error_log /var/log/nginx/error.log warn; #错误日志
pid /run/nginx.pid; #指定pid文件
worker_rlimit_nofile 35535; #nginx最大打开文件句柄数
events {
use epoll; #使用epoll网络模型
worker_connections 10240; #每个worker处理的连接数
}
http {
include mime.types; #nginx可是别的文件类型
default_type application/octet-stream; #nginx不认识的文件类型就默认下载
charset utf-8;
#定义日志格式
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#定义json格式日志
log_format json_access '{"@timestamp":"$time_iso8601",'
'"host":"$server_addr",'
'"clientip":"$remote_addr",'
'"size":$body_bytes_sent,'
'"responsetime":$request_time,'
'"upstreamtime":"$upstream_response_time",'
'"upstreamhost":"$upstream_addr",'
'"http_host":"$host",'
'"url":"$uri",'
'"domain":"$host",'
'"xff":"$http_x_forwarded_for",'
'"referer":"$http_referer",'
'"status":"$status"}';
access_log /var/log/nginx/access.log main; #访问日志
server_tokens off; #关闭显示nginx版本
client_max_body_size 200m; #文件上传大小限制
sendfile on; #高效传输
tcp_nopush on; #高效传输
tcp_nodelay on; #实时传输
keepalive_timeout 65; #长连接
gzip on; #开启压缩
gzip_disable "MSIE [1-6]\."; #针对IE浏览器不进行压缩
gzip_http_version 1.1; #压缩传输版本
gzip_comp_level 2; #压缩的等级
gzip_buffers 16 8k; #压缩的缓冲区
gzip_min_length 1024; #最小1024字节才开始压缩
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript image/jpeg; #压缩的文件类型
include /etc/nginx/conf.d/*.conf; #虚拟主机配置文件
}