# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user              nginx;
worker_processes  8;
worker_rlimit_nofile 65536;

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

pid        /usr/local/openresty/nginx/logs/nginx.pid;


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


http {
# длинные имена файлов или доменов не работали при дефалте server_names_hash_bucket_size 32
    server_names_hash_bucket_size 128;
# osv demo5 биллинг глючил без этих опций
# todo3 возможно надо это в cloudfox enterprise
    client_body_buffer_size    4m;
    proxy_buffering on;
    proxy_connect_timeout      300; #время на ожидание соединения
    proxy_send_timeout         300;
    proxy_read_timeout         300;

    proxy_buffer_size          128k;
    proxy_buffers              8 128k;
    proxy_busy_buffers_size    128k;

    proxy_temp_file_write_size 10m;
    proxy_max_temp_file_size 0;

    sendfile on;
    #sendfile_max_chunk 512k;

    tcp_nopush     on;
    tcp_nodelay    on;

    client_max_body_size 100000m;
    open_file_cache max=200000 inactive=20s;
    open_file_cache_valid 30s; 
    open_file_cache_min_uses 2;
    open_file_cache_errors on;
    gzip on;
    gzip_min_length 1200;
    gzip_proxied any;
    gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml application/json application/xml+rss application/javascript;
    gzip_disable "msie6";
    gzip_comp_level 1;
    
    # syslog-py
    log_format forpgsql '$remote_addr $remote_user $msec $request_method "$request_filename" "$server_protocol" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$server_name" "$ca_path" "$args" "$sent_http_content_type" "$http_accept"';

    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;

    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    keepalive_requests 1000;
    
    #gzip  on;

    # Для поддержки WebSocket, чтобы не проставлять везде Connection: upgrade
    # пример из документации https://nginx.org/ru/docs/http/websocket.html
    # Если выставлять "proxy_set_header Connection $http_connection;"
    # т.е. прозрачно проксировать то, что передает клиент - мы начнем передавать
    # и keep-alive, а это может сглючить, т.к. для proxy_pass дефолт Connection: close
    map $http_upgrade $connection_upgrade_ws {
        default upgrade;
        '' close;
    }

    # Для сбора статистики в cdn-analytic.cloudfox.com
    log_format clickhouselog escape=json
'{'
'"body_bytes_sent":"$body_bytes_sent",'
'"bytes_sent":"$bytes_sent",'
'"connection":"$connection",'
'"connection_requests":"$connection_requests",'
'"content_length":"$content_length",'
'"content_type":"$content_type",'
'"host":"$host",'
'"hostname":"$hostname",'
'"http_cookie":"$http_cookie",'
'"http_dnt":"$http_dnt",'
'"http_referer":"$http_referer",'
'"http_user_agent":"$http_user_agent",'
'"http_x_forwarded_for":"$http_x_forwarded_for",'
'"msec":"$msec",'
'"nginx_version":"$nginx_version",'
'"query_string":"$query_string",'
'"remote_addr":"$remote_addr",'
'"remote_port":"$remote_port",'
'"remote_user":"$remote_user",'
'"request":"$request",'
'"request_completion":"$request_completion",'
'"request_id":"$request_id",'
'"request_length":"$request_length",'
'"request_method":"$request_method",'
'"request_time":"$request_time",'
'"scheme":"$scheme",'
'"server_addr":"$server_addr",'
'"server_name":"$server_name",'
'"server_port":"$server_port",'
'"server_protocol":"$server_protocol",'
'"ssl_cipher":"$ssl_cipher",'
'"ssl_ciphers":"$ssl_ciphers",'
'"ssl_curves":"$ssl_curves",'
'"ssl_protocol":"$ssl_protocol",'
'"ssl_server_name":"$ssl_server_name",'
'"status":"$status",'
'"tcpinfo_rcv_space":"$tcpinfo_rcv_space",'
'"tcpinfo_rtt":"$tcpinfo_rtt",'
'"tcpinfo_rttvar":"$tcpinfo_rttvar",'
'"tcpinfo_snd_cwnd":"$tcpinfo_snd_cwnd",'
'"upstream_addr":"$upstream_addr",'
'"upstream_bytes_received":"$upstream_bytes_received",'
'"upstream_bytes_sent":"$upstream_bytes_sent",'
'"upstream_cache_status":"$upstream_cache_status",'
'"upstream_connect_time":"$upstream_connect_time",'
'"upstream_header_time":"$upstream_header_time",'
'"upstream_response_length":"$upstream_response_length",'
'"upstream_response_time":"$upstream_response_time",'
'"upstream_status":"$upstream_status",'
'"uri":"$uri",'
'"f":"f"'
'}';

    
    # Load config files from the /etc/nginx/conf.d directory
    # The default server is in conf.d/default.conf
    # include /etc/nginx/conf.d/*.conf;
    include /usr/local/openresty/nginx/conf.d/*.conf;

}
