daemon off;
error_log stderr;
pid /var/run/nginx.pid;

events {
	worker_connections 1024;
}

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

    server_tokens off;

    server_names_hash_bucket_size 64;
	
    #include /data/cloudflare.conf;
	
    server {
        server_name _;
        listen 80 default_server;
        listen 443 ssl http2 default_server;
        ssl_certificate /data/ssl-cert-snakeoil.pem;
        ssl_certificate_key /data/ssl-cert-snakeoil.key;
        return 444;
    }

    server {
        server_name %%DOMAIN%%;

        # These shouldn't need to be changed
        listen 80;
        return 301 https://$host$request_uri;
    }

    server {
        server_name %%DOMAIN%%;

        ssl_session_timeout 1d;
        ssl_session_cache shared:MozSSL:10m;
        ssl_session_tickets off;
        ssl_certificate /ssl/%%FULLCHAIN%%;
        ssl_certificate_key /ssl/%%PRIVKEY%%;

        # dhparams file
        ssl_dhparam /data/dhparams.pem;

        listen 443 ssl http2;
        %%HSTS%%
        
        # intermediate configuration
        ssl_protocols TLSv1.2 TLSv1.3;
        ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
        ssl_prefer_server_ciphers off;

        proxy_buffering off;

        #include /share/nginx_proxy_default*.conf;

        location / {
            proxy_pass http://homeassistant.local.hass.io:%%HA_PORT%%;
            proxy_set_header Host $host;
            proxy_redirect http:// https://;
            proxy_http_version 1.1;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
        }
    }

    #include /share/nginx_proxy/*.conf;
}
