Last active
April 25, 2024 06:20
-
-
Save pxwise/f08603f4fd13bc54e6aa to your computer and use it in GitHub Desktop.
HTML5 pushState nginx configuration
This file contains 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
# HTML5 pushState nginx configuration | |
# | |
# @see: http://stackoverflow.com/a/30515169/1774183 | |
# | |
# Server block for a client side app with directories: | |
# | |
# / | |
# /foo | |
# /foo/bar | |
# /foo/bar/baz | |
# /foo/bar/baz/123 | |
# /tacos | |
# /tacos/123 | |
server { | |
listen 80; | |
server_name example.com; | |
root /var/www/example.com; | |
gzip_static on; | |
location / { | |
try_files $uri $uri/ /index.html; | |
} | |
# Attempt to load static files, if not found route to @rootfiles | |
location ~ (.+)\.(html|json|txt|js|css|jpg|jpeg|gif|png|svg|ico|eot|otf|woff|woff2|ttf)$ { | |
try_files $uri @rootfiles; | |
} | |
# Check for app route "directories" in the request uri and strip "directories" | |
# from request, loading paths relative to root. | |
location @rootfiles { | |
rewrite ^/(foo/bar/baz|foo/bar|foo|tacos)/(.*) /$2 redirect; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you ! It solved my problem.