
# Run nginx in foreground.
daemon off;

# This is run inside Docker.
user root;

# Pid storage location.
pid /var/run/nginx.pid;

# Set number of worker processes.
worker_processes auto;

# Enables the use of JIT for regular expressions to speed-up their processing.
pcre_jit on;

# Write error log to Hass.io add-on log.
error_log /proc/1/fd/1 error;

# Load allowed environment vars
env HASSIO_TOKEN;

# Load dynamic modules.
include /etc/nginx/modules/*.conf;

# Max num of simultaneous connections by a worker process.
events {
    worker_connections 8192;
}

http {
    include /etc/nginx/includes/mime.types;

    # https://emby.media/community/index.php?/topic/93074-how-to-emby-with-nginx-with-windows-specific-tips-and-csp-options/
    server_names_hash_bucket_size 64;
    gzip_disable            "msie6";
    gzip_comp_level         6;
    gzip_min_length         1100;
    gzip_buffers            16 8k;
    gzip_proxied            any;
    gzip_types
      text/plain
      text/css
      text/js
      text/xml
      text/javascript
      application/javascript
      application/x-javascript
      application/json
      application/xml
      application/rss+xml
      image/svg+xml;
    proxy_connect_timeout 1h;

    log_format hassio '[$time_local] $status '
                        '$http_x_forwarded_for($remote_addr) '
                        '$request ($http_user_agent)';

    access_log              /proc/1/fd/1 hassio;
    client_max_body_size    4G;
    default_type            application/octet-stream;
    gzip                    on;
    keepalive_timeout       65;
    sendfile                on;
    server_tokens           off;
    tcp_nodelay             on;
    tcp_nopush              on;

    map $time_iso8601 $today {
        default "";
    }

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

    include /etc/nginx/includes/resolver.conf;
    include /etc/nginx/includes/upstream.conf;

    include /etc/nginx/servers/*.conf;
}
