-
Notifications
You must be signed in to change notification settings - Fork 0
/
edge-nginx.conf
62 lines (50 loc) · 2.21 KB
/
edge-nginx.conf
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
events {}
worker_processes auto;
http {
# Cache settings
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=edge_cache:100m max_size=5g inactive=1h use_temp_path=off;
upstream main_server {
server host.docker.internal:8080; # Main server
}
server {
listen 80;
# Health check (bypass caching)
location /health {
proxy_pass http://main_server;
proxy_no_cache 1;
proxy_cache_bypass 1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# Default cached route
location / {
proxy_cache edge_cache;
proxy_cache_key "$scheme$request_method$host$request_uri?$args";
proxy_cache_valid 200 1h; # Cache successful responses for 1 hour
proxy_cache_valid 404 5m; # Cache 404 responses for 5 minutes
proxy_cache_use_stale error timeout invalid_header http_500 http_502 http_503 http_504 updating;
proxy_cache_revalidate on; # Validate cache entries before reusing
proxy_pass http://main_server;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header X-Cache-Status $upstream_cache_status;
# Buffering and timeout settings
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_connect_timeout 5s;
proxy_read_timeout 60s;
proxy_send_timeout 60s;
# Ignore backend headers that prevent caching
proxy_ignore_headers Cache-Control Expires;
}
# Access log with cache status for monitoring
# log_format cache_status '$remote_addr - $host [$time_local] '
# '"$request" $status $body_bytes_sent '
# '"$http_referer" "$http_user_agent" '
# 'Cache: $upstream_cache_status';
# access_log /var/log/nginx/access.log cache_status;
}
}