Skip to content
Reverse Proxy

Reverse Proxy

HTTP/1.1 Reverse Proxy with Upstream Keepalive

Always enable proxy_http_version 1.1 and clear the Connection header when using keepalive pools so naati reuses upstream TCP connections across requests:

upstream app_backend {
    server 10.0.1.10:8080;
    server 10.0.1.11:8080;
    keepalive 64;
}

server {
    listen 80;
    server_name api.example.com;

    location / {
        proxy_pass http://app_backend;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        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_connect_timeout 5s;
        proxy_read_timeout 60s;
        proxy_send_timeout 60s;
    }
}

HTTP/2 Upstream (proxy_http_version 2)

naati supports HTTP/2 both on the client side and upstream:

location /h2/ {
    proxy_pass https://h2_backend;
    proxy_http_version 2;
    proxy_ssl_server_name on;
}

WebSockets & Protocol Upgrade

map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

server {
    listen 80;
    location /ws/ {
        proxy_pass http://app_backend;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_read_timeout 3600s;
    }
}

Large Uploads & Unbuffered Streaming

For large request bodies or streaming APIs, tune client_max_body_size and disable request buffering when the upstream handles streaming directly:

location /upload {
    client_max_body_size 512m;
    proxy_request_buffering off;
    proxy_pass http://app_backend;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
}