#配置启动用户为root
user root;
worker_processes 1;
events {
worker_connections 1024;
}
http {
#配置日志为json格式
log_format main '{
"@timestamp":"$time_local",
"host":"$server_addr",
"clientip":"$remote_addr",
"remoteuser":"$remoteuser",
"request":"$request",
"httpuseragent":"$httpuseragent",
"size":"$bodybytessent",
"responsetime":"$request_time",
"upstreamtime":"$upstreamresponsetime",
"upstreamhost":"$upstream_addr",
"http_host":"$host",
"url":"$uri",
"domain":"$host",
"xff":"$httpxforwarded_for",
"referer":"$http_referer",
"status":"$status"
}';
#不生效
#access_log logs/access.log main;#1、转发的日志查看
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
#负载均衡实现session共享,缺少配置流量分配和健康检查
upstream dianyunetserver {
server 102.13.22.223:8080;
server 102.13.22.224:8080;
server 102.13.22.225:8080;
ip_hash;
}
server {
listen 80;
server_name 127.0.0.1;
location / {
proxypass http://dianyunet_server;
gzip on; #开启gzip增加访问速度
gzipminlength 1k; #设置允许压缩的页面最小字节数,超过1k的文件会被压缩
gzip_buffers 16 64k; #获取多少内存用于缓存压缩结果
gziphttpversion 1.1; #识别http协议的版本
gzipcomplevel 6; #gzip压缩比(1~9),越小压缩效果越差,但是越大处理越慢,所以一般取中间值
gzip_types text/plain application/x-javascript text/css application/xml image/jpeg image/gif image/png; #对特定的MIME类型生效,js和css文件会被压缩
gzip_vary on; #设置为on会在Header里增加 "Vary: Accept-Encoding"
gzip_disable "MSIE [1-6]\."; #IE6不使用gzip
gzip_proxied any; #代理结果数据的压缩反向代理使用
proxysetheader X-Real-IP $remote_addr;
proxysetheader X-Forwarded-For $proxyaddx_forwarded_for;
#proxysetheader X-Forwarded-For $httpxforwarded_for;
proxysetheader Host $http_host;
proxyconnecttimeout 100;
proxyreadtimeout 600;
proxysendtimeout 600;
proxybuffersize 64k;
proxy_buffers 4 32k;
proxybusybuffers_size 64k;
proxytempfile_write_size 64k;
}
#日志按照天分割
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;
}
accesslog logs/nginxaccess_$year-$month-$day.log main;
}
}
评论