user www www;
worker_processes auto;
error_log  /data/wwwlogs/error_nginx.log;
pid /var/run/nginx.pid;
worker_rlimit_nofile 51200;

events {
  use epoll;
  worker_connections 51200;
  multi_accept on;
}

include /opt/verynginx/verynginx/nginx_conf/in_external.conf;
http {
    include /opt/verynginx/verynginx/nginx_conf/in_http_block.conf;

    include       mime.types;
    default_type  application/octet-stream;
    log_format urchin_utm '{"@timestamp":"$time_iso8601",'
                 '"clientip":"$clientRealIp",'
                 '"incap_client_ip":"$http_incap_client_ip",'
                 '"scheme":"$scheme",'
                 '"http_host":"$http_host",'
                 '"server_addr":"$server_addr",'
                 '"request":"$request",'
                 '"status":"$status",'
                 '"uri":"$uri",'
                 '"request_time":$request_time,'
                 '"remote_addr":"$remote_addr",'
                 '"device_token":"$http_device_token",'
                 '"s":"$http_s",'
                 '"http_cookie":"$http_cookie",'
                 '"http_referer":"$http_referer",'
                 '"http_user_agent":"$http_user_agent",'
                 '"body_bytes_sent":$body_bytes_sent,'
                 '"proxy_host":"$proxy_host",'
                 '"upstream_addr":"$upstream_addr",'
                 '"upstream_status":"$upstream_status",'
                 '"upstream_cache_status":"$upstream_cache_status",'
                 '"upstream_response_time":"$upstream_response_time"}';
    sendfile on;
    tcp_nopush     on;
    tcp_nodelay on;
    underscores_in_headers on;
    proxy_next_upstream error http_500  http_502 http_503 http_504 timeout;

    server_names_hash_max_size 2048;
    server_names_hash_bucket_size 512;
    keepalive_timeout 45s;
    client_header_timeout 15s;
    client_body_timeout 15s;
    proxy_connect_timeout 5s;
    
    variables_hash_max_size 2048;    
    server_tokens off;
    proxy_intercept_errors on;
    client_header_buffer_size 16k;
    large_client_header_buffers 4 32k;
    client_body_buffer_size  128k; 
    client_max_body_size 16m;

    gzip on;
    gzip_min_length  1k;
    gzip_buffers     16 8k;
    gzip_comp_level 6;
    gzip_types       text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/json application/javascript;
    gzip_vary on;
    proxy_cache_path /data/nginx_cache levels=1:2 keys_zone=my_zone:10m inactive=60m use_temp_path=off;
    proxy_cache_key $scheme$proxy_host$request_uri$is_args$args$http_accept_language;

    map $http_x_forwarded_for  $clientRealIp {
        ""    $remote_addr;
        ~^(?P<firstAddr>[0-9\.]+),?.*$    $firstAddr;
    }
    access_log /data/wwwlogs/access_nginx.log urchin_utm;
    limit_conn_zone $clientRealIp zone=totalConnZone:40m ;
    limit_conn  totalConnZone  50;
    limit_req_zone $clientRealIp zone=reqZone:20m  rate=20r/s;
    limit_conn_status 444;
    limit_req_status 444;
    server {
        listen       80;
        server_name 127.0.0.1 localhost;
        include /opt/verynginx/verynginx/nginx_conf/in_server_block.conf;
        location /ngx_status {
            stub_status on;
            access_log off;
            allow 127.0.0.1;
            deny all;
        }
    }
resolver 1.1.1.1 8.8.4.4 8.8.8.8 valid=60s;
    include vhost/*.conf;
 }
