user nginx;
worker_processes auto;
worker_rlimit_nofile 65535;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 16384;
multi_accept on;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" '
'rt=$request_time uct="$upstream_connect_time" '
'uht="$upstream_header_time" urt="$upstream_response_time"';
access_log off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
keepalive_requests 10000;
client_max_body_size 100M;
server_tokens off;
resolver 127.0.0.11 valid=5s ipv6=off;
map $http_x_forwarded_proto $forwarded_proto {
default $http_x_forwarded_proto;
"" $scheme;
}
map $http_x_forwarded_host $forwarded_host {
default $http_x_forwarded_host;
"" $http_host;
}
server {
listen 80 backlog=4096 reuseport;
server_name localhost;
# Variables in proxy_pass force per-request DNS resolution via the
# resolver above, so nginx survives backend container restarts.
set $cf_controlplane_backend_url "http://cf-controlplane:4444";
set $cf_dataplane_backend_url "http://cf-dataplane:4445";
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header Authorization $http_authorization;
proxy_set_header Mcp-Session-Id $http_mcp_session_id;
proxy_set_header Mcp-Protocol-Version $http_mcp_protocol_version;
proxy_set_header Mcp-Method $http_mcp_method;
proxy_set_header Mcp-Name $http_mcp_name;
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 $forwarded_proto;
proxy_set_header X-Forwarded-Host $forwarded_host;
proxy_set_header Connection "";
# Backend identity is trusted only when nginx replaces any upstream
# value at this public routing boundary.
proxy_hide_header X-CF-Integration-Backend;
location /nginx_status {
stub_status on;
allow 127.0.0.1;
allow 172.16.0.0/12;
allow 10.0.0.0/8;
deny all;
}
location = /health {
proxy_pass $cf_controlplane_backend_url;
proxy_connect_timeout 5s;
proxy_read_timeout 5s;
}
# Trailing slash is normalized away: /servers/{id}/mcp/ -> .../mcp
location ~ ^/servers/([^/]+)/mcp/?$ {
proxy_pass $cf_dataplane_backend_url/contextforge-rs/servers/$1/mcp$is_args$args;
proxy_request_buffering on;
proxy_buffering off;
proxy_cache off;
add_header X-Accel-Buffering "no" always;
add_header X-CF-Integration-Backend dataplane always;
proxy_connect_timeout 30s;
proxy_send_timeout 1h;
proxy_read_timeout 1h;
}
location / {
proxy_pass $cf_controlplane_backend_url;
add_header X-CF-Integration-Backend controlplane always;
proxy_connect_timeout 30s;
proxy_send_timeout 120s;
proxy_read_timeout 120s;
}
}
}