Skip to content

Instantly share code, notes, and snippets.

@qguv
Created July 29, 2020 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qguv/5759af47a99cd05a4381554f379609b1 to your computer and use it in GitHub Desktop.
Save qguv/5759af47a99cd05a4381554f379609b1 to your computer and use it in GitHub Desktop.
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 $uri/index.html =404;
}
# ends in extension
location ~ /[^/][^/.]*\.[a-zA-Z0-9]+$ {
root /var/www/example.com;
try_files $uri =404;
}
# ends in bare path
location ~ [^/]$ {
return 302 $uri/$query_string;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment