user nginx;
pid /var/run/nginx.pid;


worker_processes auto;
worker_rlimit_nofile 300000; # needs to be < ulimit -n

error_log /data/nginx/logs/nginx-error.log warn;

events {
    worker_connections 40000;
    multi_accept on;
}

http {
    # aggressive caching for read-only sources
    open_file_cache max=1000000 inactive=60m;
    open_file_cache_valid 60m;
    open_file_cache_min_uses 1;
    open_file_cache_errors on;

    server_tokens off;

    include /etc/nginx/mime.types;
    types {
        application/x-protobuf pbf;
    }
    default_type application/octet-stream;

    charset utf-8;

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;

    reset_timedout_connection on;
    send_timeout 20;

    max_ranges 0;

    gzip on;
    gzip_comp_level 1;
    gzip_types application/json;

    log_format access_json '{'
    '"time": "$time_iso8601", '
    '"status": $status, '
    '"request_method": "$request_method", '
    '"uri": "$uri", '
    '"request": "$request", '
    '"request_time": $request_time, '
    '"body_bytes_sent": $body_bytes_sent, '
    '"remote_addr": "$remote_addr", '
    '"http_x_forwarded_for": "$http_x_forwarded_for", '
    '"http_cf_connecting_ip": "$http_cf_connecting_ip", '
    '"http_referrer": "$http_referer", '
    '"http_user_agent": "$http_user_agent", '
    '"scheme": "$scheme", '
    '"host": "$host", '
    '"http_host": "$http_host", '
    '"http_cf_ray": "$http_cf_ray", '
    '"http_cf_ipcountry": "$http_cf_ipcountry"'
    '}';

    # access log disabled by default
    #access_log /data/nginx/logs/nginx-access.log access_json buffer=32k;
    access_log off;

    include /data/nginx/config/*;
    include /data/nginx/sites/*;
}
