S
Supanote
Sign in Sign up

Nginx SPA Single-Page App Fallback & Caching Routing

plain (nginx) 1 month ago · 31 lines · 244 views
Verified Blueprint Nginx

Optimized configuration for React, Vue, Vite, and Next export SPAs with aggressive asset caching and index.html fallback.

Quick Fetch
1# Nginx Single Page Application (SPA) Routing & Caching
2server {
3 listen 80;
4 listen [::]:80;
5 server_name app.example.com;
6 root /var/www/app/dist;
7 index index.html;
8
9 # Gzip & Brotli Compression
10 gzip on;
11 gzip_types text/plain text/css application/json application/javascript text/xml application/xml image/svg+xml;
13 # Immutable static assets (hashed bundles)
14 location ~* \.(?:css|js|woff2?|svg|png|jpg|webp)$ {
15 expires 1y;
16 add_header Cache-Control "public, immutable";
17 access_log off;
18 }
20 # SPA Client-Side Routing Fallback
21 location / {
22 try_files $uri $uri/ /index.html;
23 add_header Cache-Control "no-cache, must-revalidate";
24 }
26 # Security Headers
27 add_header X-Frame-Options "DENY" always;
28 add_header X-Content-Type-Options "nosniff" always;
29 add_header Referrer-Policy "strict-origin-when-cross-origin" always;

No replies yet

Every reply is a note. Start a discussion, ask a question, or attach a code snippet.

Related Nginx & DevOps & Infrastructure Blueprints

Production-ready configurations and diagnostics from the verified Supanote library.

All DevOps & Infrastructure →
Interactive Developer Workbench: Nginx Access & Error Log Analyzer

Parse Nginx combined access logs and upstream error traces instantly with HTTP status colorizing and secret scanning.

Open Nginx Log Analyzer →

Share Note

Open
Download SVG
Social Card Preview
Open on mobile
Point your phone camera to open this note directly

Report this note

Notification