-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnginx.conf
More file actions
executable file
·110 lines (94 loc) · 3.33 KB
/
nginx.conf
File metadata and controls
executable file
·110 lines (94 loc) · 3.33 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
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Gzip compression
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_comp_level 6;
gzip_proxied expired no-cache no-store private auth;
gzip_types
text/plain
text/css
text/xml
text/javascript
application/x-javascript
application/xml
application/javascript
application/json
application/rss+xml
application/atom+xml
image/svg+xml;
gzip_disable "MSIE [1-6]\.";
# Brotli compression (if available)
# brotli on;
# brotli_comp_level 6;
# brotli_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
server {
listen 8080;
server_name _;
root /usr/share/nginx/html;
index index.html;
# 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 "no-referrer-when-downgrade" always;
add_header Content-Security-Policy "default-src 'self' https://*.googleapis.com; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://cdnjs.cloudflare.com https://esm.sh; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self' data:;" always;
# Block access to sensitive directories and files
location ~ ^/(public|src|components|pages|services|hooks|types|node_modules|\.git) {
deny all;
return 403;
}
# Block sensitive file types
location ~* \.(ts|tsx|js\.map|css\.map|log|env|gitignore)$ {
deny all;
return 403;
}
# Block config files
location ~* (package.*\.json|tsconfig\.json|vite\.config\.ts|\.env.*|deploy.*\.sh|Dockerfile|cloudbuild\.yaml)$ {
deny all;
return 403;
}
# Cache static assets with proper extensions
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot|webp)$ {
expires 1y;
add_header Cache-Control "public, immutable";
# Enable efficient TCP connection handling
tcp_nodelay on;
sendfile on;
}
# Optimize font loading
location ~* \.(woff2|woff|ttf|eot)$ {
expires 1y;
add_header Cache-Control "public, immutable";
add_header Access-Control-Allow-Origin "*";
}
# Special handling for important files
location = /sitemap.xml {
expires 1d;
add_header Cache-Control "public";
}
location = /robots.txt {
expires 1d;
add_header Cache-Control "public";
}
location = /ads.txt {
expires 1d;
add_header Cache-Control "public";
}
# Handle client-side routing
location / {
try_files $uri $uri/ /index.html;
}
# Health check endpoint for Cloud Run
location /health {
access_log off;
return 200 "healthy\n";
add_header Content-Type text/plain;
}
}
}