Created
July 29, 2020 12:43
-
-
Save qguv/21d6c65b47b8a6e529aa5d8c2cbc49d3 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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