-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnginx.conf
84 lines (72 loc) · 2.81 KB
/
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
events {
# Maximum number of simultaneous connections
worker_connections 1024;
}
http {
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
# Upstream definition for HAProxy RPC load balancer
upstream rpc_nodes {
server 127.0.0.1:8545;
}
upstream ws_nodes {
server 127.0.0.1:8546;
}
server {
listen 8080;
# Main location for RPC traffic
location / {
# Remove any existing CORS headers from upstream
proxy_hide_header 'Access-Control-Allow-Origin';
proxy_hide_header 'Access-Control-Allow-Methods';
proxy_hide_header 'Access-Control-Allow-Headers';
proxy_hide_header 'Access-Control-Max-Age';
# Handle preflight requests
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Content-Type';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain; charset=utf-8';
add_header 'Content-Length' 0;
return 204;
}
# Add CORS headers for non-OPTIONS requests
if ($request_method != 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Content-Type';
}
# WebSocket specific configuration
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
# Route WebSocket traffic to ws_nodes, regular traffic to rpc_nodes
if ($http_upgrade = "websocket") {
proxy_pass http://ws_nodes;
}
proxy_pass http://rpc_nodes;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# Health check endpoint for Kubernetes/monitoring
# Liveness probe endpoint - always returns OK
location /health/alive {
access_log off;
return 200 "OK";
add_header Content-Type text/plain;
}
# Readiness probe endpoint - always returns OK
location /health/ready {
access_log off;
# Short timeouts for quick health check responses
proxy_connect_timeout 2s;
proxy_read_timeout 2s;
proxy_pass http://127.0.0.1:8547/health;
add_header Content-Type text/plain;
}
}
}