Created
March 16, 2026 19:19
-
-
Save hgirish/76bc67f31d56d2eb2fca8e3a01727271 to your computer and use it in GitHub Desktop.
nginx.conf.template with HTTPS redirects + Cache‑Control
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
| # Force HTTPS using Azure's X-Forwarded-Proto header | |
| server { | |
| listen 80; | |
| # Redirect HTTP → HTTPS | |
| if ($http_x_forwarded_proto = "http") { | |
| return 301 https://$host$request_uri; | |
| } | |
| # Alias domains → primary domain (HTTPS) | |
| server_name ${ALIAS_DOMAINS}; | |
| return 301 https://${PRIMARY_DOMAIN}$request_uri; | |
| } | |
| server { | |
| listen 80; | |
| # Redirect HTTP → HTTPS for primary domain | |
| if ($http_x_forwarded_proto = "http") { | |
| return 301 https://$host$request_uri; | |
| } | |
| server_name ${PRIMARY_DOMAIN}; | |
| root /usr/share/nginx/html; | |
| index index.html; | |
| # Long-term caching for hashed static assets | |
| location ~* \.(js|css|png|jpg|jpeg|gif|svg|ico|webp|woff|woff2|ttf|eot)$ { | |
| add_header Cache-Control "public, max-age=31536000, immutable"; | |
| try_files $uri =404; | |
| } | |
| # Prevent caching of index.html (SPA entry point) | |
| location = /index.html { | |
| add_header Cache-Control "no-cache, no-store, must-revalidate"; | |
| try_files $uri =404; | |
| } | |
| # SPA fallback | |
| location / { | |
| try_files $uri $uri/ /index.html; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment