Created
January 23, 2021 21:36
-
-
Save coltenkrauter/2ec75399210d3e8d33612426a37377e1 to your computer and use it in GitHub Desktop.
Nginx configuration for SPAs (Single page applications) such as React or Angular
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
# https://www.zeolearn.com/magazine/setting-caching-headers-for-a-spa-in-nginx-cache | |
server { | |
listen 80; | |
server_name localhost; | |
root /usr/share/nginx/html; | |
# X-Frame-Options is to prevent from clickJacking attack | |
add_header X-Frame-Options SAMEORIGIN; | |
# disable content-type sniffing on some browsers. | |
add_header X-Content-Type-Options nosniff; | |
# This header enables the Cross-site scripting (XSS) filter | |
add_header X-XSS-Protection "1; mode=block"; | |
add_header Referrer-Policy "no-referrer-when-downgrade"; | |
# Enables response header of "Vary: Accept-Encoding" | |
gzip_vary on; | |
location /static/settings.json { | |
try_files $uri $uri/; | |
expires -1; | |
add_header Cache-Control "no-store, no-cache, must-revalidate"; | |
} | |
location /static { | |
try_files $uri $uri/; | |
expires modified 1y; | |
add_header Cache-Control "public"; | |
access_log off; | |
} | |
location / { | |
try_files $uri $uri/ /index.html; | |
expires -1; | |
add_header Cache-Control "no-store, no-cache, must-revalidate"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment