user 						www-data;
worker_processes 			auto;
pid 						/run/nginx.pid;
include 					/etc/nginx/modules-enabled/*.conf;
worker_rlimit_nofile 		65535;

events {
    multi_accept 			on;
    worker_connections 		8000;
}

http {
    # General Settings
    charset					utf-8;
    sendfile 				on;
    tcp_nopush 				on;
    tcp_nodelay 			on;
    types_hash_max_size 	2048;
    client_max_body_size	100M;
    server_tokens 			off; # Shows nginx version
    
    # MIME Settings
    include					mime.types;
    default_type 			application/octet-stream;

    # Log Settings
    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for" '
                      '"$host" sn="$server_name" '
                      'rt=$request_time '
                      'ua="$upstream_addr" us="$upstream_status" '
                      'ut="$upstream_response_time" ul="$upstream_response_length" '
                      'cs=$upstream_cache_status' ;
    access_log 				/var/log/nginx/access.log main;
    error_log 				/var/log/nginx/error.log warn;

    # GZIP Settings
    gzip 					on;
    gzip_vary				on;
    gzip_proxied			any;
    gzip_comp_level			6;
    gzip_disable 			"msie6";
    gzip_min_length 		1024;
    gzip_types
        application/atom+xml
        application/javascript
        application/json
        application/ld+json
        application/manifest+json
        application/rss+xml
        application/vnd.geo+json
        application/vnd.ms-fontobject
        application/x-font-ttf
        application/x-web-app-manifest+json
        application/xhtml+xml
        application/xml
        font/opentype
        image/bmp
        image/svg+xml
        image/x-icon
        text/cache-manifest
        text/css
        text/plain
        text/vcard
        text/vnd.rim.location.xloc
        text/vtt
        text/x-component
        text/x-cross-domain-policy;
    
    # Limits
    limit_req_log_level  	warn;
    limit_req_zone			$binary_remote_addr zone=login:10m rate=10r/m;

    # Optimizations
    # https://www.digitalocean.com/community/tutorials/how-to-optimize-nginx-configuration
    client_body_buffer_size		10K;
    client_body_timeout			24;
    client_header_buffer_size	1k;
    large_client_header_buffers 2 1k;
    # https://gist.github.com/denji/8359866
    # reset_timedout_connection	on;
    # send_timeout				24;
    server_names_hash_bucket_size 64;

    # Virtual Host Configs
    include 				/etc/nginx/conf.d/*.conf;
    include 				/etc/nginx/sites-enabled/*;
}
