NGINX Reverse Proxy Configuration Rules
Defines NGINX reverse proxy routing to backend, frontend, Hydra, and Adminer services with security headers and JSON logging.
View sourceWhat this file does
Defines NGINX reverse proxy routing to backend, frontend, Hydra, and Adminer services with security headers and JSON logging.
When to use it
- Need to proxy multiple backend services behind a single NGINX instance
- Using Paketo Buildpacks with NGINX buildpack for containerized deployment
- Require conditional proxy routes based on environment variables
- Want structured JSON logging and security headers in a reverse proxy
Assumes this stack
NGINX Reverse Proxy Configuration Rules
Overview
This module (avarc-nginx) provides a reverse proxy using NGINX with Paketo Buildpacks. It routes requests to backend services including frontend, backend API, Hydra, and Adminer.
Architecture
- Build: Uses Paketo Buildpacks (
paketobuildpacks/builder-jammy-basewithdocker.io/paketobuildpacks/nginx) - Configuration:
nginx.confuses Paketo template syntax ({{env "VAR"}}and{{port}}) - MIME Types:
mime.typesfile is copied from resources during build
Key Responsibilities
- Reverse Proxy Routing: Routes requests to appropriate upstream services
- Security Headers: Implements security headers (X-Frame-Options, X-Content-Type-Options, Referrer-Policy)
- Request Logging: JSON-formatted access logs with configurable exclusions
- Protocol Handling: Properly handles X-Forwarded-Proto for HTTPS behind proxies
Configuration Structure
Upstream Services
backend: Spring Boot backend API (configurable viaAPP_BACKEND_HOST/APP_BACKEND_PORT)frontend: Next.js frontend (configurable viaAPP_FRONTEND_HOST/APP_FRONTEND_PORT)adminer: Database admin tool (configurable viaAPP_ADMINER_HOST/APP_ADMINER_PORT)hydra_public: Ory Hydra public API (conditional, viaENABLE_HYDRA_PROXY)hydra_admin: Ory Hydra admin API (conditional, viaENABLE_HYDRA_PROXY)
Location Blocks
/actuator: Spring Boot Actuator endpoints/v3/api-docs,/swagger-ui.html,/swagger-ui/: OpenAPI documentation/adminer/: Database administration interface/hydra/: Ory Hydra public API (OAuth2/OIDC endpoints) - conditional/hydra-admin/: Ory Hydra admin API (client management) - conditional/: Default route to frontend (Next.js)
Environment Variables
NGINX_PORT: Port for NGINX to listen onAPP_BACKEND_HOST,APP_BACKEND_PORT: Backend service locationAPP_FRONTEND_HOST,APP_FRONTEND_PORT: Frontend service locationAPP_ADMINER_HOST,APP_ADMINER_PORT: Adminer service locationENABLE_HYDRA_PROXY: Enable Hydra proxy routes ("true" to enable)APP_HYDRA_PUBLIC_HOST,APP_HYDRA_PUBLIC_PORT: Hydra public API locationAPP_HYDRA_ADMIN_HOST,APP_HYDRA_ADMIN_PORT: Hydra admin API location
Security Considerations
- Production TODO: Secure
/actuator,/swagger-ui,/adminer, and/hydra-adminendpoints - Hydra Admin API: Should be restricted with IP whitelist, authentication, and rate limiting
- Hydra Public API: Consider rate limiting and IP-based restrictions
- All security headers are set at server level
Build Process
- Maven resources plugin copies
mime.typesto project root duringprepare-package - Paketo
packCLI builds Docker image using NGINX buildpack - Buildpack processes
nginx.conftemplate at runtime - Image uses
BP_NGINX_CONF_PATH=nginx.confandBP_NGINX_STATIC_ROOT=.
Development Guidelines
- Use Paketo template syntax for environment variable substitution
- Maintain JSON logging format for structured logs
- Exclude noisy paths from logging (webpack-hmr, favicon.ico)
- Always set proper proxy headers for upstream services
- Use
proxy_http_version 1.1for HTTP/1.1 connections - Support WebSocket upgrades for frontend (Upgrade, Connection headers)
Infrastructure Guidelines
- Configure as reverse proxy (primary function)
- Implement load balancing when multiple backend instances are available
- Set up SSL/TLS for production environments
- Configure secure HTTP headers (already implemented)
- Optimize performance settings (worker processes, connections)
- Set up proper logging (JSON format implemented)
- Implement caching strategies for static content
- Monitor performance and adjust configuration as needed
Testing
- Verify all upstream services are reachable
- Test conditional Hydra proxy routes
- Validate security headers in responses
- Check JSON log format output
- Verify protocol forwarding (X-Forwarded-Proto)
What's inside
7 sections covering architecture, 4 upstream services, 6 location blocks, 8 environment variables, and build process steps
Change this for your project
- Replace
avarc-nginxwith your own module name - Replace
APP_BACKEND_HOST,APP_FRONTEND_HOST,APP_ADMINER_HOSTwith your service hostnames - Replace
ENABLE_HYDRA_PROXYwith your own feature flag if not using Hydra - Replace
BP_NGINX_CONF_PATH=nginx.confandBP_NGINX_STATIC_ROOT=.with your buildpack config
Where it goes
Save in docs/ or the repository root. Gives agents and new contributors a map of the codebase.
Worth borrowing
- Conditional upstream blocks controlled by an environment variable toggle
- JSON-formatted access logs with noise path exclusions
Related Documents
PCB Design Sources for Industry-Scale Testing
Lists GitHub repos and communities where you can download real PCB designs for testing optimization at scale.
Design Document: BharatSeva AI
Describes a 10-agent AWS system that helps India's informal workers access government schemes via voice-first, serverless architecture.
OpenClaw Enterprise Transformation Plan
Transforms a single-user AI agent into a dual-mode platform supporting both viral open-source and Fortune 500 enterprise deployments through phased security, IAM, audit, multi-tenancy, and Kubernetes features.
Qwen Image and Edit: Open-sourcing and Local GGUF Generations with Lightning
Documents the Qwen-Image and Qwen-Image-Edit models, covering architecture, training, benchmarks, ComfyUI setup, and prompting techniques for local GGUF deployment.