Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
nginx host static files, add trailing slash when using implicit index.html, preserve anchors and queries
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name example.com;
# ends in slash
location ~ ^([^#?]*/)([#?].*)?$ {
root /var/www/example.com;
try_files $1/index.html =404;
}
# ends in extension
location ~ ^([^#?]*\/[^#?\/][^#?\/.]*\.[a-zA-Z0-9]+)([#?].*)?$ {
root /var/www/example.com;
try_files $1 =404;
}
# ends in bare path
location ~ ^([^#?]*\/[^#?\/]+)([#?].*)?$ {
return 302 $1/$2;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment