Generate NGINX or other config files to proxy web traffic to back-end containers
1.0K
This project is no longer maintained.
The world has changed substantially since I wrote this. I'm currently using kubernetes with external-dns to solve this problem, and Traefik for the proxy part.
This should be considered deprecated.
A container that
Includes configuration templates for standard and SSL proxies.
Create some back end servers with appropriate labels:
docker run -d --name web1 --label proxy.host=www.example.com my-web-server
docker run -d --name web2 --label proxy.host=www.example.com my-web-server
Now create an NGINX proxy server that will be configured to proxy traffic to these systems.
docker run -d --name proxy --label proxy.notify -v /etc/nginx/conf.d -v /usr/share/nginx/html nginx
and last start the generator
docker run -d --name proxy-generator -v /var/run/docker.sock:/var/run/docker.sock --volumes-from proxy deweysasser/web-proxy-generator
Alternatively, you can use an orchestration tool. Here is an exmaple docker-compose.yml file to demonstrate capability
web1:
image: nginx
command: bash -c 'echo $$(hostname) > /usr/share/nginx/html/index.html; nginx -g "daemon off;"'
labels:
- proxy.host=www.example.com
web2:
image: nginx
command: bash -c 'echo $$(hostname) > /usr/share/nginx/html/index.html; nginx -g "daemon off;"'
labels:
- proxy.host=www.example.com
proxy:
image: nginx
volumes:
- /etc/nginx/conf.d
- /usr/share/nginx/html
ports:
- 80:80
labels:
- proxy.notify
updater:
build: .
volumes_from:
- proxy
volumes:
- /var/run/docker.sock:/var/run/docker.sock
Templates are defined in Jinja2.
You can override or extend them by arranging for files to be placed in
the /templates directory in the container (either via docker
inheritance or volume mapping)
There are command line options to override which templates are used in which context. The default is:
Alternatives include
If you are going to use SSL, you need to make sure you have your SSL
configuration in the NGINX container in /etc/nginx/ssl/ssl.conf.
Because of the way SSL works, you will need a certificate that is valid for all proxied sites. You can generate this certificate with LetsEncrypt or a commerical service. Documentation on how to do this would be a welcome contribution to this project (or I'll eventually get to it).
We will eventually support automatic LetsEncrypt certificate generation.
Content type
Image
Digest
Size
264.7 MB
Last updated
almost 9 years ago
docker pull deweysasser/web-proxy-generator