events {}

http {
    server {
        listen 80;
        server_name %SERVER_NAME;

        # directly answer initial certbot request
        location /.well-known/acme-challenge/ {
            root /var/www/certbot;
        }

        # forward all other HTTP-requests to HTTPS
        location / {
            return 301 https://$host$request_uri;
        }
    }

    server {
        listen 443 ssl;
        server_name %SERVER_NAME;

        ssl_certificate /etc/letsencrypt/live/%SERVER_NAME/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/%SERVER_NAME/privkey.pem;
        include /etc/letsencrypt/options-ssl-nginx.conf;

        location /.well-known/acme-challenge/ {
            root /var/www/certbot;
        }

        location / {
            proxy_pass http://%SERVER_NAME:8090;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
        }
    }
}

