load_module /usr/lib/nginx/modules/ngx_stream_module.so;
worker_processes auto;

events
{
  worker_connections 1024;
}

http
{
  include mime.types;
  default_type text/html;

  {# caching #}
  proxy_cache_path {{ nginx.directories.cache.general }} levels=1:2 keys_zone=cache:20m max_size=20g inactive=14d use_temp_path=off;
  proxy_cache_path {{ nginx.directories.cache.image }} levels=1:2 keys_zone=imgcache:10m inactive=60m use_temp_path=off;

  # --------------------------------------------------------------------------------
  # Tweak the hash table used to store your server_name entries:
  server_names_hash_bucket_size 64;   # size of each bucket for server_name lookups (in bytes)
  server_names_hash_max_size    512;  # maximum total buckets for the server_name hash table
  # --------------------------------------------------------------------------------

  {# logging and debugging #}
{% if enable_debug | bool %}
  {# individual log format for better debugging #}
  log_format debug '$host - $remote_addr [$time_local] '
                  '"$request" $status $body_bytes_sent '
                  '"Referer: $http_referer" '
                  '"User-Agent: $http_user_agent" '
                  '"ReqTime: $request_time" "UpstreamTime: $upstream_response_time" '
                  '"ReqLength: $request_length" "BytesSent: $bytes_sent" '
                  '"ConnRequests: $connection_requests" '
                  '"X-Forwarded-For: $http_x_forwarded_for" '
                  '"Scheme: $scheme" "Protocol: $server_protocol" "ServerName: $server_name"';
  access_log syslog:server=unix:/dev/log debug;
{% else %}
  access_log syslog:server=unix:/dev/log;
{% endif %}
  error_log syslog:server=unix:/dev/log;

  sendfile on;
  keepalive_timeout 65;

  {# gzip #}
  gzip on;
  gzip_proxied any;
  gzip_vary on;
  gzip_disable "MSIE [1-6]\.(?!.*SV1)"; # Disable for Internetexplorer 6
  gzip_comp_level 4;
  gzip_min_length 256;
  gzip_types application/atom+xml application/javascript application/xml+rss application/x-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 text/javascript text/xml;

  types_hash_max_size 4096;  
  {% for dir in nginx.directories.http.values() %}
  include {{ dir }}*.conf;
  {% endfor %}
}

# For port proxies
stream{
  include {{nginx.directories.streams}}*.conf;
}
