# Include in http {}. Enable the HTTP server first to obtain a certificate. server { listen 80; listen [::]:80; server_name static.example; location ^~ /.well-known/acme-challenge/ { root /var/lib/letsencrypt; default_type text/plain; try_files $uri =404; } location / { return 308 https://static.example$request_uri; } } server { listen 443 ssl; listen [::]:443 ssl; server_name static.example; ssl_certificate /etc/letsencrypt/live/static.example/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/static.example/privkey.pem; root /srv/www/static.example/public; index index.html; autoindex off; disable_symlinks on from=$document_root; add_header X-Content-Type-Options nosniff always; add_header Referrer-Policy no-referrer always; location ~ /\. { deny all; } location / { try_files $uri $uri/ =404; } }