mirror of
https://github.com/luxfi/nginx.git
synced 2026-11-16 21:26:33 +00:00
- Add generic /ext/ location to proxy all extension APIs to luxd - Configure proper CORS headers for all API endpoints - Support WebSocket connections for any /ext path - Ensure health, info, metrics, and blockchain APIs are accessible - Root path (/) continues to proxy to C-Chain RPC for compatibility
78 lines
3.4 KiB
SYSTEMD
78 lines
3.4 KiB
SYSTEMD
# LUX Network API (C-Chain)
|
|
server {
|
|
listen 8080;
|
|
listen [::]:8080;
|
|
server_name api.lux.network rpc.lux.network;
|
|
|
|
# Generic /ext location - proxies all extension APIs to luxd
|
|
location /ext/ {
|
|
proxy_pass http://127.0.0.1:9630/ext/;
|
|
proxy_http_version 1.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;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
|
|
# Support WebSocket upgrade for any /ext path that needs it
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection "upgrade";
|
|
|
|
# Add CORS headers
|
|
add_header 'Access-Control-Allow-Origin' '*' always;
|
|
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
|
|
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
|
|
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
|
|
|
|
# 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' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
|
|
add_header 'Access-Control-Max-Age' 1728000;
|
|
add_header 'Content-Type' 'text/plain; charset=utf-8';
|
|
add_header 'Content-Length' 0;
|
|
return 204;
|
|
}
|
|
|
|
# Timeout settings for long-running requests
|
|
proxy_read_timeout 60s;
|
|
proxy_connect_timeout 60s;
|
|
proxy_send_timeout 60s;
|
|
}
|
|
|
|
# C-Chain RPC (default for root path)
|
|
location / {
|
|
# Add CORS headers
|
|
add_header 'Access-Control-Allow-Origin' '*' always;
|
|
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
|
|
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
|
|
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
|
|
|
|
# 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' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
|
|
add_header 'Access-Control-Max-Age' 1728000;
|
|
add_header 'Content-Type' 'text/plain; charset=utf-8';
|
|
add_header 'Content-Length' 0;
|
|
return 204;
|
|
}
|
|
|
|
# Proxy to C-Chain RPC endpoint
|
|
proxy_pass http://127.0.0.1:9630/ext/bc/C/rpc;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection 'upgrade';
|
|
proxy_set_header Host $host;
|
|
proxy_cache_bypass $http_upgrade;
|
|
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;
|
|
|
|
# Timeout settings for long-running requests
|
|
proxy_read_timeout 60s;
|
|
proxy_connect_timeout 60s;
|
|
proxy_send_timeout 60s;
|
|
}
|
|
} |