enable list of domains for a virtual host

Enables the autoproxy to handle multiple domains for a virtual
host: e.g. a container can handle requests to www.somedomain.de
and somedomain.de
This commit is contained in:
Joachim Lusiardi 2016-04-03 12:05:51 +02:00
parent 04e6d506a1
commit 7196d03ec8
2 changed files with 14 additions and 16 deletions

View File

@ -2,14 +2,14 @@
This image attaches to the docker event queue and creates/removes proxy settings in the contained nginx. This image attaches to the docker event queue and creates/removes proxy settings in the contained nginx.
## How it works ## How it works
Containers that should be proxied neet meta information in the environment variable *PROXY_DATA* available. Containers that should be proxied need meta information in the environment variable *PROXY_DATA* available.
This variable must be of the following format: This variable must be of the following format:
`PROXY_DATA=server_name:test.com,port:80` `PROXY_DATA=server_names:test.com;www.test.com,port:80`
The following options are possible: The following options are possible:
* **server_name**(required) the name of the virtual host * **server_names**(required) the names of the virtual hosts separated by ";"
* **port**(optional, defaults to 80) the port on the target container * **port**(optional, defaults to 80) the port on the target container
* **ip**(optional, defaults to listen on all IPs) the IP on which the proxy should listen. * **ip**(optional, defaults to listen on all IPs) the IP on which the proxy should listen.
* **location**(optional) if the proxied web application is not running on the /-path * **location**(optional) if the proxied web application is not running on the /-path
@ -17,7 +17,7 @@ The following options are possible:
## Starting the container ## Starting the container
Since the container uses Docker's internal event reporting, it needs access to the daemon. At the Since the container uses Docker's internal event reporting, it needs access to the daemon. At the
moment, only access via UNIX socket ist possible. Because of that, the socket has to be handed moment, only access via UNIX socket is possible. Because of that, the socket has to be handed
into the container (*-v /var/run/docker.sock:/var/run/docker.sock*). into the container (*-v /var/run/docker.sock:/var/run/docker.sock*).
### Single IP / All IPs ### Single IP / All IPs
@ -29,7 +29,7 @@ Run the container like this:
That means that the container exposes all Web Apps on all IPs. Do **not** use the *ip* option from above on the target containers. The *PROXY_DATA* environment variables would be something like That means that the container exposes all Web Apps on all IPs. Do **not** use the *ip* option from above on the target containers. The *PROXY_DATA* environment variables would be something like
`PROXY_DATA=server_name:cooldomain.test.com,port:8080,location=/webApp` `PROXY_DATA=server_names:cooldomain.test.com,port:8080,location=/webApp`
### Multiple IPs ### Multiple IPs
This option is used if your Docker Host has multiple IPs (perhaps a public IP in the internet and a private IP on a VPN). It is possible to expose some Web Apps only to the private network. This option is used if your Docker Host has multiple IPs (perhaps a public IP in the internet and a private IP on a VPN). It is possible to expose some Web Apps only to the private network.
@ -40,7 +40,6 @@ One container must be started for each IP that should host Web Apps. For example
If a target container does **not** have the *ip* option set, it listens on **all** IP adresses and will be handled by both containers. If a target container does **not** have the *ip* option set, it listens on **all** IP adresses and will be handled by both containers.
If a container uses, e.g., If a container uses, e.g.,
`PROXY_DATA=server_name:cooldomain.test.com,port:8080,location=/webApp,ip=10.1.2.3` `PROXY_DATA=server_names:cooldomain.test.com,port:8080,location=/webApp,ip=10.1.2.3`
then it will be only available on the private 10.1.2.3 IP (perhaps using a VPN). then it will be only available on the private 10.1.2.3 IP (perhaps using a VPN).

View File

@ -26,7 +26,7 @@ server {
location_template="""# proxy for container '$containername' location_template="""# proxy for container '$containername'
server { server {
listen $listen; listen $listen;
server_name $name; server_name $names;
location / { location / {
return 301 $$scheme://$name/$location; return 301 $$scheme://$name/$location;
} }
@ -94,7 +94,7 @@ def handle_container(id):
'containername': extract_name(inspect_data), 'containername': extract_name(inspect_data),
'ip': extract_ip(inspect_data), 'ip': extract_ip(inspect_data),
'location': get_if_available(proxy_data, 'location', ''), 'location': get_if_available(proxy_data, 'location', ''),
'name': get_if_available(proxy_data, 'server_name', ''), 'names': get_if_available(proxy_data, 'server_names', '').replace(';', ' '),
'port': get_if_available(proxy_data, 'port', 80), 'port': get_if_available(proxy_data, 'port', 80),
'listen': '*:80' 'listen': '*:80'
} }
@ -190,4 +190,3 @@ if __name__ == '__main__':
handle_container(container_id) handle_container(container_id)
reload_nginx_configuration() reload_nginx_configuration()