Skip to content

Instantly share code, notes, and snippets.

@pxwise
Last active April 25, 2024 06:20
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pxwise/f08603f4fd13bc54e6aa to your computer and use it in GitHub Desktop.
Save pxwise/f08603f4fd13bc54e6aa to your computer and use it in GitHub Desktop.
HTML5 pushState nginx configuration
# 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;
}
}
@shamim-42
Copy link

Thank you ! It solved my problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment