chain-rdeveloper portal
build

Nginx Service

Overview

Nginx serves as the reverse proxy, load balancer, and web server for the Chainr platform, routing requests to appropriate backend services.

Responsibilities

  • Request routing and load balancing

  • No TLS: nginx listens on plain HTTP on port 80 inside the stack, published as 8000 locally and not published at all on the dev host. There, Cloudflare reaches it only through cloudflared over the internal edge-network; TLS ends at the Cloudflare edge and the tunnel is encrypted (see Cloudflare Tunnel)

  • Taking the client address from CF-Connecting-IP, trusted only from edge-network, so rate limits and logs see the real client

  • Static file serving

  • Rate limiting and security

  • Request logging and monitoring

Configuration

Server Blocks

Current local routing (from modules/nginx/conf.d/default.conf) uses domain-based server blocks:

  • auth.dev.datachainr.com → svc-auth (container upstream on port 3000)

  • app.dev.datachainr.com → frontend core + /api/ to svc-bff (container upstream on port 4000)

  • dev.datachainr.com → public frontend

App/API Example

server {
    listen 80;
    server_name app.dev.datachainr.com;

    location = /auth-verify {
        internal;
        proxy_pass http://core_auth/verify;
        proxy_pass_request_body off;
        proxy_set_header Content-Length "";
        proxy_set_header Cookie $http_cookie;
        proxy_set_header X-Original-URI $request_uri;
    }

    location /api/ {
        auth_request /auth-verify;
        proxy_pass http://core_app/;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    location / {
        auth_request /auth-verify;
        proxy_pass http://frontend_app;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

Load Balancing

upstream core_auth {
    server modules-svc-auth-1:3000 resolve;
}

upstream core_app {
    server modules-svc-bff-1:4000 resolve;
}

upstream frontend_app {
    server modules-fe-core-1:5173 resolve;
}

server {
    location /api/ {
        proxy_pass http://core_app/;
    }
}

Security Features

  • Rate limiting per IP/client

  • Request size limits

  • CORS configuration

  • Security headers (HSTS, CSP, etc.)

  • SSL/TLS configuration

Performance Optimizations

  • Gzip compression

  • Caching headers for static assets

  • Connection pooling

  • Worker process optimization

Monitoring

  • Access logs

  • Error logs

  • Health check endpoints

  • Metrics collection

Configuration Files

  • /etc/nginx/nginx.conf - Main configuration

  • /etc/nginx/conf.d/*.conf - Service-specific configs

  • /etc/nginx/sites-enabled/ - Enabled sites