clawchain/deploy/nginx/api-gateway.conf
2026-05-15 19:18:10 +03:00

530 lines
16 KiB
Plaintext

# ClawChain Production API Gateway
# Nginx reverse proxy for api.clawchain.io / rpc.clawchain.io
#
# Upstream targets should be adjusted for your deployment topology.
# In K8s, replace localhost with service DNS names.
upstream clawchain_rest {
server 127.0.0.1:1317;
keepalive 32;
}
upstream clawchain_rpc {
server 127.0.0.1:26657;
keepalive 32;
}
upstream clawchain_grpc {
server 127.0.0.1:9090;
keepalive 32;
}
upstream clawchain_faucet {
server 127.0.0.1:8888;
keepalive 8;
}
upstream clawchain_web {
server 127.0.0.1:3000;
keepalive 16;
}
upstream inference_sidecar {
server 127.0.0.1:8090;
keepalive 8;
}
upstream clawchain_explorer {
server 127.0.0.1:8080;
keepalive 16;
}
upstream clawchain_dex {
server 127.0.0.1:3001;
keepalive 16;
}
upstream clawchain_eventsd {
server 127.0.0.1:8891;
keepalive 8;
}
upstream clawchain_notifyd {
server 127.0.0.1:8892;
keepalive 8;
}
upstream clawchain_docs {
server 127.0.0.1:8091;
keepalive 8;
}
upstream clawchain_landing {
server 127.0.0.1:8093;
keepalive 8;
}
# Rate limiting zones
limit_req_zone $binary_remote_addr zone=api_general:10m rate=30r/s;
limit_req_zone $binary_remote_addr zone=api_broadcast:10m rate=5r/s;
limit_req_zone $binary_remote_addr zone=faucet_limit:10m rate=1r/m;
limit_req_zone $binary_remote_addr zone=rpc_general:10m rate=20r/s;
limit_req_zone $binary_remote_addr zone=ws_limit:10m rate=5r/s;
# === api.clawchain.io — REST/LCD API ===
server {
listen 443 ssl http2;
server_name api.clawchain.io;
ssl_certificate /etc/ssl/clawchain/api.clawchain.io.crt;
ssl_certificate_key /etc/ssl/clawchain/api.clawchain.io.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
# 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 "Content-Type, Authorization, x-cosmos-block-height" always;
add_header Access-Control-Max-Age 86400 always;
# Security headers
add_header X-Content-Type-Options nosniff always;
add_header X-Frame-Options DENY always;
add_header Referrer-Policy strict-origin-when-cross-origin always;
# Handle CORS preflight
if ($request_method = OPTIONS) {
return 204;
}
# Health check
location /healthz {
access_log off;
return 200 '{"status":"ok"}';
add_header Content-Type application/json;
}
# Cosmos SDK REST/LCD endpoints
location / {
limit_req zone=api_general burst=60 nodelay;
proxy_pass http://clawchain_rest;
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;
proxy_set_header Connection "";
proxy_connect_timeout 5s;
proxy_read_timeout 30s;
proxy_send_timeout 10s;
# Cache GET responses briefly
proxy_cache_valid 200 2s;
proxy_cache_use_stale error timeout updating;
}
# Broadcast endpoints — stricter rate limit
location ~ ^/cosmos/tx/v1beta1/txs$ {
limit_req zone=api_broadcast burst=10 nodelay;
proxy_pass http://clawchain_rest;
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;
proxy_set_header Connection "";
}
# Max body size for tx broadcast
client_max_body_size 1m;
}
# === rpc.clawchain.io — CometBFT RPC ===
server {
listen 443 ssl http2;
server_name rpc.clawchain.io;
ssl_certificate /etc/ssl/clawchain/rpc.clawchain.io.crt;
ssl_certificate_key /etc/ssl/clawchain/rpc.clawchain.io.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
add_header Access-Control-Allow-Origin "*" always;
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS" always;
add_header Access-Control-Allow-Headers "Content-Type" always;
add_header X-Content-Type-Options nosniff always;
if ($request_method = OPTIONS) {
return 204;
}
# WebSocket endpoint for CometBFT subscriptions
location /websocket {
limit_req zone=ws_limit burst=10 nodelay;
proxy_pass http://clawchain_rpc/websocket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_read_timeout 600s;
proxy_send_timeout 600s;
}
# HTTP RPC endpoints
location / {
limit_req zone=rpc_general burst=40 nodelay;
proxy_pass http://clawchain_rpc;
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;
proxy_set_header Connection "";
proxy_connect_timeout 5s;
proxy_read_timeout 30s;
}
}
# === grpc.clawchain.io — gRPC endpoint ===
server {
listen 443 ssl http2;
server_name grpc.clawchain.io;
ssl_certificate /etc/ssl/clawchain/grpc.clawchain.io.crt;
ssl_certificate_key /etc/ssl/clawchain/grpc.clawchain.io.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
location / {
grpc_pass grpc://clawchain_grpc;
grpc_set_header X-Real-IP $remote_addr;
grpc_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
grpc_read_timeout 30s;
grpc_send_timeout 10s;
}
}
# === faucet.clawchain.io — Testnet faucet ===
server {
listen 443 ssl http2;
server_name faucet.clawchain.io;
ssl_certificate /etc/ssl/clawchain/faucet.clawchain.io.crt;
ssl_certificate_key /etc/ssl/clawchain/faucet.clawchain.io.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
add_header Access-Control-Allow-Origin "*" always;
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS" always;
add_header Access-Control-Allow-Headers "Content-Type" always;
if ($request_method = OPTIONS) {
return 204;
}
location / {
limit_req zone=faucet_limit burst=3 nodelay;
proxy_pass http://clawchain_faucet;
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;
client_max_body_size 4k;
}
}
# === inference.clawchain.io — Inference sidecar SSE ===
server {
listen 443 ssl http2;
server_name inference.clawchain.io;
ssl_certificate /etc/ssl/clawchain/inference.clawchain.io.crt;
ssl_certificate_key /etc/ssl/clawchain/inference.clawchain.io.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
add_header Access-Control-Allow-Origin "*" always;
add_header Access-Control-Allow-Methods "GET, OPTIONS" always;
add_header Access-Control-Allow-Headers "Content-Type" always;
if ($request_method = OPTIONS) {
return 204;
}
# SSE streaming endpoint — long-lived connections
location /stream/ {
proxy_pass http://inference_sidecar;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Connection "";
# SSE requires buffering off and long timeouts
proxy_buffering off;
proxy_cache off;
proxy_read_timeout 600s;
chunked_transfer_encoding off;
}
location / {
proxy_pass http://inference_sidecar;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
# === app.clawchain.io — Web dashboard ===
server {
listen 443 ssl http2;
server_name app.clawchain.io;
ssl_certificate /etc/ssl/clawchain/app.clawchain.io.crt;
ssl_certificate_key /etc/ssl/clawchain/app.clawchain.io.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
root /srv/clawchain-web/dist;
index index.html;
# SPA fallback — serve index.html for client-side routes
location / {
try_files $uri $uri/ /index.html;
}
# Static assets — long cache
location ~* \.(js|css|png|jpg|svg|ico|woff2?)$ {
expires 30d;
add_header Cache-Control "public, immutable";
}
}
# === explorer.clawchain.io — Block explorer ===
server {
listen 443 ssl http2;
server_name explorer.clawchain.io;
ssl_certificate /etc/ssl/clawchain/explorer.clawchain.io.crt;
ssl_certificate_key /etc/ssl/clawchain/explorer.clawchain.io.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
add_header X-Content-Type-Options nosniff always;
add_header X-Frame-Options SAMEORIGIN always;
add_header Referrer-Policy strict-origin-when-cross-origin always;
location / {
proxy_pass http://clawchain_explorer;
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;
}
location ~* \.(js|css|png|jpg|svg|ico|woff2?)$ {
proxy_pass http://clawchain_explorer;
expires 30d;
add_header Cache-Control "public, immutable";
}
}
# === dex.clawchain.io — ClawDEX trading app ===
server {
listen 443 ssl http2;
server_name dex.clawchain.io;
ssl_certificate /etc/ssl/clawchain/dex.clawchain.io.crt;
ssl_certificate_key /etc/ssl/clawchain/dex.clawchain.io.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
add_header X-Content-Type-Options nosniff always;
add_header X-Frame-Options DENY always;
add_header Referrer-Policy strict-origin-when-cross-origin always;
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; connect-src 'self' https://api.clawchain.io https://rpc.clawchain.io wss://rpc.clawchain.io" always;
location / {
proxy_pass http://clawchain_dex;
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;
}
location ~* \.(js|css|png|jpg|svg|ico|woff2?)$ {
proxy_pass http://clawchain_dex;
expires 30d;
add_header Cache-Control "public, immutable";
}
}
# === events.clawchain.io — WebSocket event proxy ===
server {
listen 443 ssl http2;
server_name events.clawchain.io;
ssl_certificate /etc/ssl/clawchain/events.clawchain.io.crt;
ssl_certificate_key /etc/ssl/clawchain/events.clawchain.io.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
add_header Access-Control-Allow-Origin "*" always;
add_header Access-Control-Allow-Methods "GET, OPTIONS" always;
add_header Access-Control-Allow-Headers "Content-Type" always;
if ($request_method = OPTIONS) {
return 204;
}
# WebSocket endpoint
location /ws {
limit_req zone=ws_limit burst=10 nodelay;
proxy_pass http://clawchain_eventsd;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_read_timeout 600s;
proxy_send_timeout 600s;
}
location / {
proxy_pass http://clawchain_eventsd;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
# === notify.clawchain.io — Notification service ===
server {
listen 443 ssl http2;
server_name notify.clawchain.io;
ssl_certificate /etc/ssl/clawchain/notify.clawchain.io.crt;
ssl_certificate_key /etc/ssl/clawchain/notify.clawchain.io.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
add_header Access-Control-Allow-Origin "*" always;
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS" always;
add_header Access-Control-Allow-Headers "Content-Type, Authorization" always;
if ($request_method = OPTIONS) {
return 204;
}
# WebSocket notifications
location /ws/ {
limit_req zone=ws_limit burst=10 nodelay;
proxy_pass http://clawchain_notifyd;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_read_timeout 600s;
}
# REST API
location / {
limit_req zone=api_general burst=30 nodelay;
proxy_pass http://clawchain_notifyd;
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;
}
}
# === docs.clawchain.io — Documentation site ===
server {
listen 443 ssl http2;
server_name docs.clawchain.io;
ssl_certificate /etc/ssl/clawchain/docs.clawchain.io.crt;
ssl_certificate_key /etc/ssl/clawchain/docs.clawchain.io.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
add_header X-Content-Type-Options nosniff always;
add_header X-Frame-Options SAMEORIGIN always;
location / {
proxy_pass http://clawchain_docs;
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;
}
location ~* \.(js|css|png|jpg|svg|ico|woff2?)$ {
proxy_pass http://clawchain_docs;
expires 30d;
add_header Cache-Control "public, immutable";
}
}
# === clawchain.io — Landing page ===
server {
listen 443 ssl http2;
server_name clawchain.io www.clawchain.io;
ssl_certificate /etc/ssl/clawchain/clawchain.io.crt;
ssl_certificate_key /etc/ssl/clawchain/clawchain.io.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
add_header X-Content-Type-Options nosniff always;
add_header X-Frame-Options DENY always;
add_header Referrer-Policy strict-origin-when-cross-origin always;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
location / {
proxy_pass http://clawchain_landing;
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;
}
location ~* \.(js|css|png|jpg|svg|ico|woff2?)$ {
proxy_pass http://clawchain_landing;
expires 30d;
add_header Cache-Control "public, immutable";
}
}
# === HTTP → HTTPS redirect ===
server {
listen 80;
server_name api.clawchain.io rpc.clawchain.io grpc.clawchain.io
faucet.clawchain.io inference.clawchain.io app.clawchain.io
explorer.clawchain.io dex.clawchain.io events.clawchain.io
notify.clawchain.io docs.clawchain.io clawchain.io www.clawchain.io;
return 301 https://$host$request_uri;
}