user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    tcp_nopush     on;

    keepalive_timeout  120;

    tcp_nodelay on;

    client_body_buffer_size  50M;
    proxy_connect_timeout    240;
    proxy_read_timeout       240;
    proxy_send_timeout       240;
    proxy_buffer_size        50M;
    proxy_buffers            4 50M;
    proxy_busy_buffers_size 50M;
    proxy_temp_file_write_size 50M;

    gzip on;
    gzip_min_length  1k;
    gzip_buffers     4 16k;
    gzip_http_version 1.1;
    gzip_comp_level 2;
    gzip_types       text/plain application/x-javascript text/css application/xml;
    gzip_vary on;
    
    log_format json #定义日志格式
       '{"@timestamp":"$time_iso8601",' 
       '"slbip":"$remote_addr",' 
       '"clientip":"$http_x_forwarded_for",' 
       '"serverip":"$server_addr",' 
       '"size":$body_bytes_sent,' 
       '"responsetime":$request_time,' 
       '"host":"$host",' 
       '"method":"$request_method",' 
       '"requesturi":"$request_uri",' 
       '"url":"$uri",'  
       '"upstream_addr":"$upstream_addr",' 
       '"upstream_status":"$upstream_status",' 
       '"upstream_cache_status":"$upstream_cache_status",'
       '"upstream_response_time":"$upstream_response_time",' 
       '"appversion":"$HTTP_APP_VERSION",' 
       '"referer":"$http_referer",' 
       '"agent":"$http_user_agent",' 
       '"status":"$status",' 
       '"devicecode":"$HTTP_HA"}';
	#upstream的负载均衡，weight是权重，可以根据机器配置定义权重。
	#weigth参数表示权值，权值越高被分配到的几率越大，此处为配置权值，默认为轮巡方式。
    upstream localhost {
      ip_hash;
      server 192.168.137.110:18080 weight=1; # 节点1
      server 192.168.137.111:18080 weight=1; # 节点2
    }
    server {
      listen 80;    # nginx端口号
      server_name 192.168.137.112;  # nginx服务名
      access_log  /var/log/nginx/smartbi.log json; #日志格式及保存路径
      location / {
        proxy_pass http://localhost;
        include proxy_params;
      } 
    }
    include /etc/nginx/conf.d/*.conf;
}