Skip to content

Instantly share code, notes, and snippets.

@hgirish
Created March 16, 2026 19:19
Show Gist options
  • Select an option

  • Save hgirish/76bc67f31d56d2eb2fca8e3a01727271 to your computer and use it in GitHub Desktop.

Select an option

Save hgirish/76bc67f31d56d2eb2fca8e3a01727271 to your computer and use it in GitHub Desktop.
nginx.conf.template with HTTPS redirects + Cache‑Control
# 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