Skip to content
simple dockerized nginx reverseproxy w/ jinja2 templating using j2cli
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Circle CI

Simple dockerized nginx reverseproxy w/ Jinja2 templating using j2cli.

/etc/nginx/nginx.conf is created from nginx.tmpl with environment variables passed to docker

example nginx.tmpl

used environment variables:

RESOLVER = dns resolver (ex.
SERVER_NAME = server name used for nginx (ex.
BACKEND_ADDR = backend address (ex.
BACKEND_PORT = backend port (ex. 4000)
user  nginx;
daemon off;
worker_processes  1;

error_log  /proc/self/fd/2 warn;
pid        /var/run/;

events {
    worker_connections  1024;

http {
    resolver {{ RESOLVER }};
    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"';

    access_log  /proc/self/fd/1 main;
    sendfile        on;
    keepalive_timeout  65;

server {
        listen 80;
        server_name {{ SERVER_NAME }};
        access_log /proc/self/fd/1;
        error_log /proc/self/fd/2;
        location / {
            proxy_pass http://{{ BACKEND_ADDR }}:{{ BACKEND_PORT }}$request_uri?;
            proxy_set_header Host $server_name;


docker build -t myimage .


Passing environment variables yourself

docker run -p 80:80 -e VARIABLE=value myimage

Works with links too

docker run -p 80:80 --link backendimage:backendimage myimage

Ideal for tutum

You can’t perform that action at this time.