This repository has been archived on 2020-08-01. You can view files and clone it, but cannot push or open issues or pull requests.
nginx-proxy/README.md

54 lines
2.4 KiB
Markdown
Raw Normal View History

2014-05-05 22:15:18 +02:00
nginx-proxy sets up a container running nginx and [docker-gen][1]. docker-gen generate reverse proxy configs for nginx and reloads nginx when containers they are started and stopped.
2014-05-05 19:01:40 +02:00
2014-05-05 22:13:51 +02:00
See [Automated Nginx Reverse Proxy for Docker][2] for why you might want to use this.
2014-05-20 17:39:08 +02:00
### Usage
2014-05-05 22:13:51 +02:00
To run it:
2014-09-05 01:34:49 +02:00
$ docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock jwilder/nginx-proxy
2014-05-05 22:13:51 +02:00
2014-10-22 04:39:34 +02:00
Then start any containers you want proxied with an env var `VIRTUAL_HOST=subdomain.youdomain.com`
2014-05-05 22:13:51 +02:00
2014-09-05 01:34:49 +02:00
$ docker run -e VIRTUAL_HOST=foo.bar.com ...
2014-05-05 22:13:51 +02:00
Provided your DNS is setup to forward foo.bar.com to the a host running nginx-proxy, the request will be routed to a container with the VIRTUAL_HOST env var set.
2014-05-20 17:39:08 +02:00
### Multiple Ports
If your container exposes multiple ports, nginx-proxy will default to the service running on port 80. If you need to specify a different port, you can set a VIRTUAL_PORT env var to select a different one. If your container only exposes one port and it has a VIRTUAL_HOST env var set, that port will be selected.
2014-05-05 22:13:51 +02:00
[1]: https://github.com/jwilder/docker-gen
[2]: http://jasonwilder.com/blog/2014/03/25/automated-nginx-reverse-proxy-for-docker/
2014-08-19 17:42:43 +02:00
### Multiple Hosts
2014-11-16 05:47:38 +01:00
If you need to support multipe virtual hosts for a container, you can separate each entry with commas. For example, `foo.bar.com,baz.bar.com,bar.com` and each host will be setup the same.
### Separate Containers
nginx-proxy can also be run as two separate containers using the [jwilder/docker-gen](https://index.docker.io/u/jwilder/docker-gen/)
image and the official [nginx](https://registry.hub.docker.com/_/nginx/) image.
You may want to do this to prevent having the docker socket bound to a publicly exposed container service.
To run nginx proxy as a separate container you'll need to have [nginx.tmpl](https://github.com/jwilder/nginx-proxy/blob/master/nginx.tmpl) on your host system.
First start nginx with a volume:
$ docker run -d -p 80:80 --name nginx -v /tmp/nginx:/etc/nginx/conf.d -t nginx
Then start the docker-gen container with the shared volume and template:
```
$ docker run --volumes-from nginx \
-v /var/run/docker.sock:/tmp/docker.sock \
2014-10-22 02:29:31 +02:00
-v $(pwd):/etc/docker-gen/templates \
-t docker-gen -notify-sighup nginx -watch --only-published /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
```
Finally, start your containers with `VIRTUAL_HOST` environment variables.
$ docker run -e VIRTUAL_HOST=foo.bar.com ...