#user nobody;
#工作进程数,一般设置为cpu核心数
worker_processes 4;
worker_rlimit_nofile 65535;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
#==最大连接数,一般设置为cpu*2048
worker_connections 2048;
}
http {
#文件扩展名与文件类型映射表
include mime.types;
#默认文件类型
default_type application/octet-stream;
#开启高效文件传输模式
sendfile on;
#长连接超时时间,单位是秒
keepalive_timeout 60;
#配置日志格式
log_format main escape=json '{ "time": "$year-$month-$day $hour:$minutes:$seconds", '
'"request_id": "$request_id",'
'"request": "$request",'
'"remote_addr": "$remote_addr",'
'"costime": "$request_time",'
'"realtime": "$upstream_response_time",'
'"status": $status,'
'"x_forwarded": "$http_x_forwarded_for",'
'"referer": "$http_referer",'
'"upstr_addr": "$upstream_addr",'
'"bytes":$body_bytes_sent,'
'"body": "$request_body",'
'"agent": "$http_user_agent" },';
access_log logs/$year-$month-$day-$hour-access.log main;
#启用Gzip压缩
#gzip on;
#gzip_min_length 1k;
#gzip_comp_level 9;
#gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
#gzip_vary on;
#gzip_disable "MSIE [1-6]\.";
#服务器的集群
#服务器集群名字,windows需要修改hosts文件
upstream localhost {
#服务器配置 weight是权重的意思,权重越大,分配的概率越大。
server 127.0.0.1:8446 weight=1;
server 127.0.0.1:8447 weight=1;
server 127.0.0.1:8448 weight=1;
}
#当配置多个server节点时,默认server names的缓存区大小就不够了,需要手动设置大一点
server_names_hash_bucket_size 512;
#server表示虚拟主机可以理解为一个站点,可以配置多个server节点搭建多个站点
#每一个请求进来确定使用哪个server由server_name确定
server {
listen 8445;
server_name localhost;
#编码格式,避免url参数乱码
charset utf-8;
if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})") {
set $year $1;
set $month $2;
set $day $3;
set $hour $4;
set $minutes $5;
set $seconds $6;
}
proxy_set_header request_id $request_id;
#location用来匹配同一域名下多个URI的访问规则
#比如动态资源如何跳转,静态资源如何跳转等
#location后面跟着的/代表匹配规则
location / {
#站点根目录,可以是相对路径,也可以是绝对路径
root html;
#默认主页
index index.html index.htm;
#转发后端站点地址,一般用于做软负载,轮询后端服务器
proxy_pass http://localhost;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}