mirror of
https://github.com/thib8956/nginx-proxy
synced 2025-07-01 14:25:46 +00:00
Honor VIRTUAL_PORT + DEBUG flag + fallback entry
The VIRTUAL_PORT environment variable should always be honored. Even when the related port is not exposed. Fix for nging-proxy/nginx-proxy#1132. This commit also add the DEBUG environment variable which enables more verbose comments in the nginx comfiguration file to help troubleshooting unreachable containers. Finaly it fixes nging-proxy/nginx-proxy#1105 as well by defining only one fallback entry per upstream block.
This commit is contained in:
45
README.md
45
README.md
@ -82,17 +82,21 @@ NginX does not support scoped IPv6 resolvers. In [docker-entrypoint.sh](./docker
|
||||
|
||||
By default, docker uses IPv6-to-IPv4 NAT. This means all client connections from IPv6 addresses will show docker's internal IPv4 host address. To see true IPv6 client IP addresses, you must [enable IPv6](https://docs.docker.com/config/daemon/ipv6/) and use [ipv6nat](https://github.com/robbertkl/docker-ipv6nat). You must also disable the userland proxy by adding `"userland-proxy": false` to `/etc/docker/daemon.json` and restarting the daemon.
|
||||
|
||||
### 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.
|
||||
|
||||
[1]: https://github.com/jwilder/docker-gen
|
||||
[2]: http://jasonwilder.com/blog/2014/03/25/automated-nginx-reverse-proxy-for-docker/
|
||||
|
||||
### 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.
|
||||
|
||||
### Virtual Ports
|
||||
|
||||
When your container exposes only one port, nginx-proxy will default to this port, else to port 80.
|
||||
|
||||
If you need to specify a different port, you can set a `VIRTUAL_PORT` env var to select a different one. This variable cannot be set to more than one port.
|
||||
|
||||
For each host defined into `VIRTUAL_HOST`, the associated virtual port is retrieved by order of precedence:
|
||||
1. From the `VIRTUAL_PORT` environment variable
|
||||
1. From the container's exposed port if there is only one
|
||||
1. From the default port 80 when none of the above methods apply
|
||||
|
||||
### 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](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).
|
||||
@ -424,6 +428,33 @@ will be used on any virtual host which does not have a `/etc/nginx/vhost.d/{VIRT
|
||||
#### Per-VIRTUAL_HOST `server_tokens` configuration
|
||||
Per virtual-host `servers_tokens` directive can be configured by passing appropriate value to the `SERVER_TOKENS` environment variable. Please see the [nginx http_core module configuration](https://nginx.org/en/docs/http/ngx_http_core_module.html#server_tokens) for more details.
|
||||
|
||||
### Troubleshooting
|
||||
|
||||
In case you can't access your VIRTUAL_HOST, set `DEBUG=true` in the client container's environment and have a look at the generated nginx configuration file `/etc/nginx/conf.d/default`:
|
||||
|
||||
```
|
||||
$ docker exec <nginx-proxy-instance> cat /etc/nginx/conf.d/default
|
||||
```
|
||||
Especially at `upstream` definition blocks which should look like:
|
||||
|
||||
```
|
||||
# foo.example.com
|
||||
upstream foo.example.com {
|
||||
## Can be connected with "my_network" network
|
||||
# Exposed ports: [{ <exposed_port1> tcp } { <exposed_port2> tcp } ...]
|
||||
# Default virtual port: <exposed_port|80>
|
||||
# VIRTUAL_PORT: <VIRTUAL_PORT>
|
||||
# foo
|
||||
server 172.18.0.9:<Port>;
|
||||
# Fallback entry
|
||||
server 127.0.0.1 down;
|
||||
}
|
||||
```
|
||||
|
||||
The effective `Port` is retrieved by order of precedence:
|
||||
1. From the `VIRTUAL_PORT` environment variable
|
||||
1. From the container's exposed port if there is only one
|
||||
1. From the default port 80 when none of the above methods apply
|
||||
|
||||
### Contributing
|
||||
|
||||
|
Reference in New Issue
Block a user