Created
December 21, 2023 04:45
-
-
Save tshipenchko/7facb0bb58614807f69c2dcf39ec87a4 to your computer and use it in GitHub Desktop.
Minimal nginx SPA config
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
### SRC: https://github.com/steebchen/nginx-spa | |
server { | |
listen 80 default_server; | |
gzip on; | |
gzip_min_length 1000; | |
gzip_types text/plain text/xml application/javascript text/css; | |
root /app; | |
# normal routes | |
# serve given url and default to index.html if not found | |
# e.g. /, /user and /foo/bar will return index.html | |
location / { | |
add_header Cache-Control "no-store"; | |
try_files $uri $uri/index.html /index.html; | |
} | |
# files | |
# for all routes matching a dot, check for files and return 404 if not found | |
# e.g. /file.js returns a 404 if not found | |
location ~ \.(?!html) { | |
add_header Cache-Control "public, max-age=2678400"; | |
try_files $uri =404; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Comment the
add_header Cache-Control "public, max-age=2678400";
part if you don't want any caching. Useful for development.