-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathnginx.conf
More file actions
134 lines (120 loc) · 4.9 KB
/
Copy pathnginx.conf
File metadata and controls
134 lines (120 loc) · 4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# =============================================================================
# Nginx Configuration for FlowWink (SPA)
# =============================================================================
# Optimized for:
# - Single Page Application routing (all routes -> index.html)
# - Static asset caching with proper headers
# - Gzip compression
# - Security headers
# - Social media crawler detection for SSR meta tags
# =============================================================================
# Detect social media crawlers for SSR meta tag rendering
# These bots need server-rendered OG tags since they don't execute JavaScript
map $http_user_agent $is_social_crawler {
default 0;
"~*facebookexternalhit" 1;
"~*Facebot" 1;
"~*Twitterbot" 1;
"~*LinkedInBot" 1;
"~*WhatsApp" 1;
"~*Slackbot" 1;
"~*Discordbot" 1;
"~*TelegramBot" 1;
"~*Pinterestbot" 1;
"~*Googlebot" 1;
"~*bingbot" 1;
}
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
# Gzip compression
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_types
text/plain
text/css
text/xml
text/javascript
application/javascript
application/json
application/xml+rss
application/rss+xml
font/truetype
font/opentype
application/vnd.ms-fontobject
image/svg+xml;
# Security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
# Static assets with long-term caching (hashed filenames from Vite)
location /assets/ {
expires 1y;
add_header Cache-Control "public, immutable";
access_log off;
}
# Favicon and other root assets
location ~* \.(ico|png|jpg|jpeg|gif|svg|webp|woff|woff2|ttf|eot)$ {
expires 1y;
add_header Cache-Control "public, immutable";
access_log off;
}
# index.html - no cache (always fetch latest)
location = /index.html {
add_header Cache-Control "no-cache, must-revalidate";
try_files $uri =404;
}
# SPA routing with social crawler detection
# Social crawlers get redirected to render-page edge function for SSR meta tags
# Regular users get the SPA
location / {
# Route social crawlers to SSR endpoint for proper OG tags
# IMPORTANT: Replace SUPABASE_PROJECT_URL with your actual Supabase URL
# Example: https://abcdefghijklmnop.supabase.co
if ($is_social_crawler) {
# Uncomment and configure the following lines for production:
# rewrite ^(.*)$ /functions/v1/render-page?path=$1 break;
# proxy_pass SUPABASE_PROJECT_URL;
# proxy_set_header Host $proxy_host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto $scheme;
# For now, fall through to SPA (social sharing will use index.html defaults)
# Configure the proxy_pass above with your Supabase URL to enable SSR
}
# Normal SPA routing
try_files $uri $uri/ /index.html;
add_header Cache-Control "no-cache, must-revalidate";
}
# Proxy sitemap.xml to Supabase edge function
# IMPORTANT: Replace SUPABASE_PROJECT_URL with your actual Supabase URL
# Example: https://abcdefghijklmnop.supabase.co
location = /sitemap.xml {
# Uncomment and configure for production:
# proxy_pass SUPABASE_PROJECT_URL/functions/v1/sitemap-xml;
# proxy_set_header Host $proxy_host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto $scheme;
# proxy_set_header X-Forwarded-Host $host;
# proxy_cache_valid 200 1h;
# Fallback: return empty sitemap until proxy is configured
default_type application/xml;
return 200 '<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"></urlset>';
}
# Proxy robots.txt (optional: can also be a static file)
location = /robots.txt {
default_type text/plain;
return 200 'User-agent: *\nAllow: /\nSitemap: https://$host/sitemap.xml\n';
}
# Health check endpoint for container orchestration
location /health {
access_log off;
return 200 "healthy\n";
add_header Content-Type text/plain;
}
}