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.

Multiple Hosts

If you need to support multiple 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.

Wildcard Hosts

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, 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.

Multiple Networks

With the addition of overlay networking in Docker 1.9, your nginx-proxy container may need to connect to backend containers on multiple networks. By default, if you don't pass the --net flag when your nginx-proxy container is created, it will only be attached to the default bridge network. This means that it will not be able to connect to containers on networks other than bridge.

If you want your nginx-proxy container to be attached to a different network, you must pass the --net=my-network option in your docker create or docker run command. At the time of this writing, only a single network can be specified at container creation time. To attach to other networks, you can use the docker network connect command after your container is created:

Let's Encrypt SSL Support

Wildcard Certificates

Wildcard certificates and keys should be named after the domain name with a .crt and .key extension.For example VIRTUAL_HOST=foo.bar.com would use cert name bar.com.crt and bar.com.key.

SNI

If your certificate(s) supports multiple domain names, you can start a container with CERT_NAME=<name>to identify the certificate to be used. For example, a certificate for *.foo.com and *.bar.comcould be named shared.crt and shared.key. A container running with VIRTUAL_HOST=foo.bar.comand CERT_NAME=shared will then use this shared cert.

The default behavior for the proxy when port 80 and 443 are exposed is as follows:

If a container has a usable cert, port 80 will redirect to 443 for that container so that HTTPSis always preferred when available.

If the container does not have a usable cert, a 503 will be returned.

Note that in the latter case, a browser may get an connection error as no certificate is availableto establish a connection. A self-signed or generic cert named default.crt and default.keywill allow a client browser to make a SSL connection (likely w/ a warning) and subsequently receivea 503.

To serve traffic in both SSL and non-SSL modes without redirecting to SSL, you can include theenvironment variable HTTPS_METHOD=noredirect (the default is HTTPS_METHOD=redirect). You can alsodisable the non-SSL site entirely with HTTPS_METHOD=nohttp. HTTPS_METHOD must be specifiedon each container for which you want to override the default behavior. If HTTPS_METHOD=noredirect isused, Strict Transport Security (HSTS) is disabled to prevent HTTPS users from being redirected by theclient. If you cannot get to the HTTP site after changing this setting, your browser has probably cachedthe HSTS policy and is automatically redirecting you back to HTTPS. You will need to clear your browser'sHSTS cache or use an incognito window / different browser.

Basic Authentication Support

In order to be able to secure your virtual host, you have to create a file named as its equivalent VIRTUAL_HOST variable on directory/etc/nginx/htpasswd/$VIRTUAL_HOST

NOTE: If you provide this file it will replace the defaults; you may want to check the .tmpl file to make sure you have all of the needed options.

NOTE: The default configuration blocks the Proxy HTTP request header from being sent to downstream servers. This prevents attackers from using the so-called httpoxy attack. There is no legitimate reason for a client to send this header, and there are many vulnerable languages / platforms (CVE-2016-5385, CVE-2016-5386, CVE-2016-5387, CVE-2016-5388, CVE-2016-1000109, CVE-2016-1000110, CERT-VU#797896).

Proxy-wide

To add settings on a proxy-wide basis, add your configuration file under /etc/nginx/conf.d using a name ending in .conf.

This can be done in a derived image by creating the file in a RUN command or by COPYing the file into conf.d:

Per-VIRTUAL_HOST

To add settings on a per-VIRTUAL_HOST basis, add your configuration file under /etc/nginx/vhost.d. Unlike in the proxy-wide case, which allows multiple config files with any name ending in .conf, the per-VIRTUAL_HOST file must be named exactly after the VIRTUAL_HOST.

In order to allow virtual hosts to be dynamically configured as backends are added and removed, it makes the most sense to mount an external directory as /etc/nginx/vhost.d as opposed to using derived images or mounting individual configuration files.

For example, if you have a virtual host named app.example.com, you could provide a custom configuration for that host as follows:

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:

Per-VIRTUAL_HOST default configuration

If you want most of your virtual hosts to use a default single configuration and then override on a few specific ones, add those settings to the /etc/nginx/vhost.d/default file. This filewill be used on any virtual host which does not have a /etc/nginx/vhost.d/{VIRTUAL_HOST} file associated with it.

Per-VIRTUAL_HOST location configuration

To add settings to the "location" block on a per-VIRTUAL_HOST basis, add your configuration file under /etc/nginx/vhost.djust 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:

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:

Per-VIRTUAL_HOST location default configuration

If you want most of your virtual hosts to use a default single location block configuration and then override on a few specific ones, add those settings to the /etc/nginx/vhost.d/default_location file. This filewill be used on any virtual host which does not have a /etc/nginx/vhost.d/{VIRTUAL_HOST} file associated with it.

Contributing

Before submitting pull requests or issues, please check github to make sure an existing issue or pull request is not already open.