Complete documentation
This commit is contained in:
parent
13bb99c4d2
commit
2eb977589c
1 changed files with 22 additions and 9 deletions
31
README.md
31
README.md
|
@ -8,7 +8,7 @@ See [Automated Nginx Reverse Proxy for Docker][2] for why you might want to use
|
||||||
|
|
||||||
To run it:
|
To run it:
|
||||||
|
|
||||||
$ docker run -d --net=host -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy
|
$ docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy
|
||||||
|
|
||||||
Then start any containers you want proxied with an env var `VIRTUAL_HOST=subdomain.youdomain.com`
|
Then start any containers you want proxied with an env var `VIRTUAL_HOST=subdomain.youdomain.com`
|
||||||
|
|
||||||
|
@ -33,6 +33,19 @@ If you need to support multiple virtual hosts for a container, you can separate
|
||||||
|
|
||||||
You can also use wildcards at the beginning and the end of host name, like `*.bar.com` or `foo.bar.*`. Or even a regular expression, which can be very useful in conjunction with a wildcard DNS service like [xip.io](http://xip.io), using `~^foo\.bar\..*\.xip\.io` will match `foo.bar.127.0.0.1.xip.io`, `foo.bar.10.0.2.2.xip.io` and all other given IPs. More information about this topic can be found in the nginx documentation about [`server_names`](http://nginx.org/en/docs/http/server_names.html).
|
You can also use wildcards at the beginning and the end of host name, like `*.bar.com` or `foo.bar.*`. Or even a regular expression, which can be very useful in conjunction with a wildcard DNS service like [xip.io](http://xip.io), using `~^foo\.bar\..*\.xip\.io` will match `foo.bar.127.0.0.1.xip.io`, `foo.bar.10.0.2.2.xip.io` and all other given IPs. More information about this topic can be found in the nginx documentation about [`server_names`](http://nginx.org/en/docs/http/server_names.html).
|
||||||
|
|
||||||
|
### Multiple Networks
|
||||||
|
|
||||||
|
With the new overlay network, your proxy can be deal with many containers in many networks. Default, if you don't use ```--net``` flag, your proxy will be attached at ```bridge``` default network. You can define your container with ```--net=your_network``` option.
|
||||||
|
|
||||||
|
If your proxy try to access at a container in an unattached network, the request is successful.
|
||||||
|
|
||||||
|
#### Connect Another Network
|
||||||
|
|
||||||
|
In current Docker release (1.9), you can create a container with only one network. To attach others networks, you can use this command.
|
||||||
|
```
|
||||||
|
docker network connect my_network my_container
|
||||||
|
```
|
||||||
|
|
||||||
### SSL Backends
|
### SSL Backends
|
||||||
|
|
||||||
If you would like to connect to your backend using HTTPS instead of HTTP, set `VIRTUAL_PROTO=https` on the backend container.
|
If you would like to connect to your backend using HTTPS instead of HTTP, set `VIRTUAL_PROTO=https` on the backend container.
|
||||||
|
@ -41,7 +54,7 @@ If you would like to connect to your backend using HTTPS instead of HTTP, set `V
|
||||||
|
|
||||||
To set the default host for nginx use the env var `DEFAULT_HOST=foo.bar.com` for example
|
To set the default host for nginx use the env var `DEFAULT_HOST=foo.bar.com` for example
|
||||||
|
|
||||||
$ docker run -d --net=host -p 80:80 -e DEFAULT_HOST=foo.bar.com -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy
|
$ docker run -d -p 80:80 -e DEFAULT_HOST=foo.bar.com -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy
|
||||||
|
|
||||||
|
|
||||||
### Separate Containers
|
### Separate Containers
|
||||||
|
@ -56,13 +69,13 @@ To run nginx proxy as a separate container you'll need to have [nginx.tmpl](http
|
||||||
First start nginx with a volume:
|
First start nginx with a volume:
|
||||||
|
|
||||||
|
|
||||||
$ docker run -d --net=host -p 80:80 --name nginx -v /tmp/nginx:/etc/nginx/conf.d -t nginx
|
$ 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:
|
Then start the docker-gen container with the shared volume and template:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ docker run --volumes-from nginx \
|
$ docker run --volumes-from nginx \
|
||||||
--net=host \
|
\
|
||||||
-v /var/run/docker.sock:/tmp/docker.sock:ro \
|
-v /var/run/docker.sock:/tmp/docker.sock:ro \
|
||||||
-v $(pwd):/etc/docker-gen/templates \
|
-v $(pwd):/etc/docker-gen/templates \
|
||||||
-t jwilder/docker-gen -notify-sighup nginx -watch -only-exposed /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
|
-t jwilder/docker-gen -notify-sighup nginx -watch -only-exposed /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
|
||||||
|
@ -79,7 +92,7 @@ certificates or optionally specifying a cert name (for SNI) as an environment va
|
||||||
|
|
||||||
To enable SSL:
|
To enable SSL:
|
||||||
|
|
||||||
$ docker run -d --net=host -p 80:80 -p 443:443 -v /path/to/certs:/etc/nginx/certs -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy
|
$ docker run -d -p 80:80 -p 443:443 -v /path/to/certs:/etc/nginx/certs -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy
|
||||||
|
|
||||||
The contents of `/path/to/certs` should contain the certificates and private keys for any virtual
|
The contents of `/path/to/certs` should contain the certificates and private keys for any virtual
|
||||||
hosts in use. The certificate and keys should be named after the virtual host with a `.crt` and
|
hosts in use. The certificate and keys should be named after the virtual host with a `.crt` and
|
||||||
|
@ -128,7 +141,7 @@ In order to be able to secure your virtual host, you have to create a file named
|
||||||
/etc/nginx/htpasswd/$VIRTUAL_HOST
|
/etc/nginx/htpasswd/$VIRTUAL_HOST
|
||||||
|
|
||||||
```
|
```
|
||||||
$ docker run -d --net=host -p 80:80 -p 443:443 \
|
$ docker run -d -p 80:80 -p 443:443 \
|
||||||
-v /path/to/htpasswd:/etc/nginx/htpasswd \
|
-v /path/to/htpasswd:/etc/nginx/htpasswd \
|
||||||
-v /path/to/certs:/etc/nginx/certs \
|
-v /path/to/certs:/etc/nginx/certs \
|
||||||
-v /var/run/docker.sock:/tmp/docker.sock:ro \
|
-v /var/run/docker.sock:/tmp/docker.sock:ro \
|
||||||
|
@ -176,7 +189,7 @@ RUN { \
|
||||||
|
|
||||||
Or it can be done by mounting in your custom configuration in your `docker run` command:
|
Or it can be done by mounting in your custom configuration in your `docker run` command:
|
||||||
|
|
||||||
$ docker run -d --net=host -p 80:80 -p 443:443 -v /path/to/my_proxy.conf:/etc/nginx/conf.d/my_proxy.conf:ro -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy
|
$ docker run -d -p 80:80 -p 443:443 -v /path/to/my_proxy.conf:/etc/nginx/conf.d/my_proxy.conf:ro -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy
|
||||||
|
|
||||||
#### Per-VIRTUAL_HOST
|
#### Per-VIRTUAL_HOST
|
||||||
|
|
||||||
|
@ -186,7 +199,7 @@ In order to allow virtual hosts to be dynamically configured as backends are add
|
||||||
|
|
||||||
For example, if you have a virtual host named `app.example.com`, you could provide a custom configuration for that host as follows:
|
For example, if you have a virtual host named `app.example.com`, you could provide a custom configuration for that host as follows:
|
||||||
|
|
||||||
$ docker run -d --net=host -p 80:80 -p 443:443 -v /path/to/vhost.d:/etc/nginx/vhost.d:ro -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy
|
$ docker run -d -p 80:80 -p 443:443 -v /path/to/vhost.d:/etc/nginx/vhost.d:ro -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy
|
||||||
$ { echo 'server_tokens off;'; echo 'client_max_body_size 100m;'; } > /path/to/vhost.d/app.example.com
|
$ { echo 'server_tokens off;'; echo 'client_max_body_size 100m;'; } > /path/to/vhost.d/app.example.com
|
||||||
|
|
||||||
If you are using multiple hostnames for a single container (e.g. `VIRTUAL_HOST=example.com,www.example.com`), the virtual host configuration file must exist for each hostname. If you would like to use the same configuration for multiple virtual host names, you can use a symlink:
|
If you are using multiple hostnames for a single container (e.g. `VIRTUAL_HOST=example.com,www.example.com`), the virtual host configuration file must exist for each hostname. If you would like to use the same configuration for multiple virtual host names, you can use a symlink:
|
||||||
|
@ -206,7 +219,7 @@ just like the previous section except with the suffix `_location`.
|
||||||
|
|
||||||
For example, if you have a virtual host named `app.example.com` and you have configured a proxy_cache `my-cache` in another custom file, you could tell it to use a proxy cache as follows:
|
For example, if you have a virtual host named `app.example.com` and you have configured a proxy_cache `my-cache` in another custom file, you could tell it to use a proxy cache as follows:
|
||||||
|
|
||||||
$ docker run -d --net=host -p 80:80 -p 443:443 -v /path/to/vhost.d:/etc/nginx/vhost.d:ro -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy
|
$ docker run -d -p 80:80 -p 443:443 -v /path/to/vhost.d:/etc/nginx/vhost.d:ro -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy
|
||||||
$ { echo 'proxy_cache my-cache;'; echo 'proxy_cache_valid 200 302 60m;'; echo 'proxy_cache_valid 404 1m;' } > /path/to/vhost.d/app.example.com_location
|
$ { echo 'proxy_cache my-cache;'; echo 'proxy_cache_valid 200 302 60m;'; echo 'proxy_cache_valid 404 1m;' } > /path/to/vhost.d/app.example.com_location
|
||||||
|
|
||||||
If you are using multiple hostnames for a single container (e.g. `VIRTUAL_HOST=example.com,www.example.com`), the virtual host configuration file must exist for each hostname. If you would like to use the same configuration for multiple virtual host names, you can use a symlink:
|
If you are using multiple hostnames for a single container (e.g. `VIRTUAL_HOST=example.com,www.example.com`), the virtual host configuration file must exist for each hostname. If you would like to use the same configuration for multiple virtual host names, you can use a symlink:
|
||||||
|
|
Reference in a new issue