user www-data;
worker_processes  8;
timer_resolution 1ms;
worker_rlimit_nofile 65530;
worker_priority -5;

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

events {
    worker_connections  32768;
    use kqueue;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile       on;
    aio            on;
    directio        512;
    output_buffers  1 128k;
    tcp_nopush     on;
    send_timeout 10;
    keepalive_timeout  65;
    reset_timedout_connection on;
    client_body_buffer_size 256k;
    client_body_timeout 120;
    client_max_body_size 10m;
    large_client_header_buffers 8 32k;

    proxy_next_upstream error;

    gzip on;
    gzip_min_length 1100;
    gzip_buffers 64 8k;
    gzip_comp_level 3;
    gzip_http_version 1.0;
    gzip_proxied any;
    gzip_types text/plain application/xml application/x-javascript text/css text/xml;

    resolver 127.0.0.1;

    fastcgi_buffers 16 32k;
    fastcgi_buffer_size 64k;

    proxy_buffering on;
    proxy_buffers 16 32k;
    proxy_buffer_size 64k;


    log_format  main  '"$remote_addr" $host $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" $request_id $upstream_addr $upstream_response_time';

    upstream push {
        ip_hash;
        server push1:8800 weight=1;
        server push2:8800 weight=1;
        keepalive 128;
    }
    upstream     hsseupstr  {
        server      hsse1:8811;
        server      hsse2:8811;
    }
    upstream     mainhttp  {
        server      server1:8200;
        server      server1:8200;
    }

    map $http_upgrade $connection_upgrade {
        default upgrade;
        ''      close;
    }


    server {
        listen 10.0.0.1:80;

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

        set_real_ip_from 10.0.0.2;
        set_real_ip_from 10.0.0.3;
        real_ip_header X-Real-IP;


        proxy_set_header Host      $host;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Request-Id $request_id;

        location / {
            proxy_pass http://mainhttp;
            proxy_connect_timeout 1s;
            proxy_read_timeout 30s;
        }

        location /events/ {
            proxy_pass http://hsseupstr;
            proxy_http_version 1.1;
            keepalive_timeout 1d;
            proxy_read_timeout 1d;
            proxy_buffering off;
            proxy_connect_timeout 86400s;
            chunked_transfer_encoding off;
            proxy_next_upstream off;
            access_log  /var/log/nginx/hsse.log  main;
            add_header Access-Control-Allow-Origin *;
        }
    }

    server {
        listen 10.0.0.5:80;

        access_log  /var/log/nginx/push-access.log  main;
        error_log  /var/log/nginx/push-error.log;

        location / {
            proxy_pass http://push;
            proxy_http_version 1.1;

            proxy_set_header Host      $host;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header X-Request-Id $request_id;

            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;

            keepalive_timeout 1d;
            proxy_read_timeout 1d;
        }
    }

    server {
        listen 80 accept_filter=httpready;
    }
}