# Run nginx in foreground.
daemon off;

# This is run inside Docker.
user nginx;

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

# Set number of worker processes.
worker_processes 1;

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

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

# Load allowed environment vars
env SUPERVISOR_TOKEN;

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

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

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

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

    access_log              off;
    client_max_body_size    100m;
    default_type            application/octet-stream;
    gzip                    on;
    gzip_disable            "msie6";
    gzip_proxied            any;
    keepalive_timeout       2;
    sendfile                on;
    server_tokens           off;
    tcp_nodelay             on;
    tcp_nopush              on;

    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;

    map $http_x_forwarded_proto $fastcgi_https {
      default off;
      "~https" on;
    }

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

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