server {
    listen 80 default_server;
    listen [::]:80 default_server;

    server_name _;
    root /var/www/html;

    location /.well-known/acme-challenge {
        try_files $uri $uri/ =404;
    }

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

server {
    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;

    ssl_certificate /etc/letsencrypt/live/{{ hostname }}/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/{{ hostname }}/privkey.pem;

    server_name _;
    root /var/www/html;
    index index.html;

    location ~ ^/~(.+?)(/.*)?$ {
        alias /home/$1/public_html/$2;
        autoindex on;
        #try_files $2 $2/ = 404;
    }

    location / {
        try_files $uri $uri/ =404;
    }
}
