##
# Basic Settings
##

tcp_nodelay on;
keepalive_timeout 65;
server_tokens off;
proxy_ssl_server_name on;
proxy_http_version    1.1;

gzip_http_version     1.1;
gzip_proxied     any;
gzip_types       text/css text/plain text/xml application/xml application/javascript application/x-javascript text/javascript application/json text/x-json;
gzip_vary        on;
gzip_comp_level  1;
gzip_disable     "MSIE [1-6]\.";

server_names_hash_bucket_size  96;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Upstreams
##

upstream solr {
    server solr:8983;
}

# solr https
server {
        server_name ${SERVERNAME};

        listen 443 ssl;

        root /var/www/html;
        index index.html index.htm;

        access_log /etc/nginx/logs/access_prod.log;
        error_log /etc/nginx/logs/error_prod.log;

        ssl_certificate           ${PEMPATH}live/${SERVERNAME}/fullchain.pem;
        ssl_certificate_key       ${PEMPATH}live/${SERVERNAME}/privkey.pem;

        location / {
            proxy_pass            http://solr;
            # uncomment for debug:
            access_log off;
        }

        location ^~ /robots.txt {
            proxy_pass            http://solr;
            access_log off;
        }

        location ^~ /favicon.ico {
            access_log off;
            log_not_found off;
        }

        location = /health {
            access_log off;
            add_header 'Content-Type' 'application/json';
            return 200 '{"status":"UP"}';
        }
}

# certbot http only
server {
        server_name ${SERVERNAME};

        listen 80;
        listen [::]:80;

        root /var/www/html;
        index index.html index.htm;

        access_log /etc/nginx/logs/access_prod.log;
        error_log /etc/nginx/logs/error_prod.log;

        location / {
            return 301 https://$host$request_uri;
        }

        location ^~ /.well-known/acme-challenge/ {
            allow all;
            default_type "text/plain";
        }

        location = /health {
            access_log off;
            add_header 'Content-Type' 'application/json';
            return 200 '{"status":"UP"}';
        }
}