Previous Page

Automated Infrastructure Tooling

Python Jinja2 Nginx Docker

A containerised sidecar that fetches routing configuration from a backend API, serialises it to YAML, and drives Nginx through Jinja2 templates — eliminating manual config changes across environments.

The motivation was simple: SSHing into servers to deploy the Nginx configs whenever routing rules changed was slow and error-prone. The goal was a self-contained container that could pull its own configuration from a backend API and reconfigure Nginx automatically.

At startup (and on a polling interval), the Python script calls the backend API to retrieve the current routing and proxy rules. The API response is parsed and written out as a YAML file — a clean, human-readable intermediate representation that decouples the API contract from the template logic.

Jinja2 then reads the YAML file and renders the final Nginx .conf. This separation means the template can be evolved independently of the fetch logic, and the YAML file doubles as an audit trail of what config was actually applied. Once rendered, the script tests the Nginx configuration syntax and triggers a graceful reload inside the container.

Key Architectural Highlights

  • Built a Python script that polls a backend API for the latest routing rules and serialises the response into a structured YAML configuration file.
  • Used Jinja2 to render Nginx .conf files directly from the YAML output, keeping templates declarative and the generated config always in sync with the backend state.
  • Packaged the Python script and Nginx together in a single Docker container, so the full fetch-parse-configure cycle runs as one cohesive unit with no external dependencies.