mirror of
https://github.com/thib8956/nginx-proxy
synced 2025-07-01 14:25:46 +00:00
Merge branch 'main' into remove_scoped
This commit is contained in:
87
README.md
87
README.md
@ -1,5 +1,9 @@
|
||||

|
||||
  [](https://travis-ci.org/jwilder/nginx-proxy) [](https://hub.docker.com/r/jwilder/nginx-proxy 'DockerHub') [](https://hub.docker.com/r/jwilder/nginx-proxy 'DockerHub')
|
||||
[](https://github.com/nginx-proxy/nginx-proxy/actions/workflows/test.yml)
|
||||
[](https://github.com/nginx-proxy/nginx-proxy/releases)
|
||||

|
||||
[](https://hub.docker.com/r/nginxproxy/nginx-proxy "Click to view the image on Docker Hub")
|
||||
[](https://hub.docker.com/r/nginxproxy/nginx-proxy 'DockerHub')
|
||||
[](https://hub.docker.com/r/nginxproxy/nginx-proxy 'DockerHub')
|
||||
|
||||
|
||||
nginx-proxy sets up a container running nginx and [docker-gen][1]. docker-gen generates reverse proxy configs for nginx and reloads nginx when containers are started and stopped.
|
||||
@ -10,7 +14,7 @@ See [Automated Nginx Reverse Proxy for Docker][2] for why you might want to use
|
||||
|
||||
To run it:
|
||||
|
||||
$ docker run -d -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 nginxproxy/nginx-proxy
|
||||
|
||||
Then start any containers you want proxied with an env var `VIRTUAL_HOST=subdomain.youdomain.com`
|
||||
|
||||
@ -24,17 +28,17 @@ Provided your DNS is setup to forward foo.bar.com to the host running nginx-prox
|
||||
|
||||
The nginx-proxy images are available in two flavors.
|
||||
|
||||
#### jwilder/nginx-proxy:latest
|
||||
#### nginxproxy/nginx-proxy:latest
|
||||
|
||||
This image uses the debian:jessie based nginx image.
|
||||
This image uses the debian:buster based nginx image.
|
||||
|
||||
$ docker pull jwilder/nginx-proxy:latest
|
||||
$ docker pull nginxproxy/nginx-proxy:latest
|
||||
|
||||
#### jwilder/nginx-proxy:alpine
|
||||
#### nginxproxy/nginx-proxy:alpine
|
||||
|
||||
This image is based on the nginx:alpine image. Use this image to fully support HTTP/2 (including ALPN required by recent Chrome versions). A valid certificate is required as well (see eg. below "SSL Support using letsencrypt" for more info).
|
||||
This image is based on the nginx:alpine image. Use this image to fully support HTTP/2 (including ALPN required by recent Chrome versions). A valid certificate is required as well (see eg. below "SSL Support using an ACME CA" for more info).
|
||||
|
||||
$ docker pull jwilder/nginx-proxy:alpine
|
||||
$ docker pull nginxproxy/nginx-proxy:alpine
|
||||
|
||||
### Docker Compose
|
||||
|
||||
@ -43,7 +47,7 @@ version: '2'
|
||||
|
||||
services:
|
||||
nginx-proxy:
|
||||
image: jwilder/nginx-proxy
|
||||
image: nginxproxy/nginx-proxy
|
||||
ports:
|
||||
- "80:80"
|
||||
volumes:
|
||||
@ -51,8 +55,11 @@ services:
|
||||
|
||||
whoami:
|
||||
image: jwilder/whoami
|
||||
expose:
|
||||
- "8000"
|
||||
environment:
|
||||
- VIRTUAL_HOST=whoami.local
|
||||
- VIRTUAL_PORT=8000
|
||||
```
|
||||
|
||||
```shell
|
||||
@ -65,7 +72,7 @@ I'm 5b129ab83266
|
||||
|
||||
You can activate the IPv6 support for the nginx-proxy container by passing the value `true` to the `ENABLE_IPV6` environment variable:
|
||||
|
||||
$ docker run -d -p 80:80 -e ENABLE_IPV6=true -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy
|
||||
$ docker run -d -p 80:80 -e ENABLE_IPV6=true -v /var/run/docker.sock:/tmp/docker.sock:ro nginxproxy/nginx-proxy
|
||||
|
||||
#### Scoped IPv6 Resolvers
|
||||
|
||||
@ -98,7 +105,7 @@ If you want your `nginx-proxy` container to be attached to a different network,
|
||||
|
||||
```console
|
||||
$ docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro \
|
||||
--name my-nginx-proxy --net my-network jwilder/nginx-proxy
|
||||
--name my-nginx-proxy --net my-network nginxproxy/nginx-proxy
|
||||
$ docker network connect my-other-network my-nginx-proxy
|
||||
```
|
||||
|
||||
@ -119,7 +126,7 @@ allow 172.16.0.0/12;
|
||||
deny all;
|
||||
```
|
||||
|
||||
When internal-only access is enabled, external clients with be denied with an `HTTP 403 Forbidden`
|
||||
When internal-only access is enabled, external clients will be denied with an `HTTP 403 Forbidden`
|
||||
|
||||
> If there is a load-balancer / reverse proxy in front of `nginx-proxy` that hides the client IP (example: AWS Application/Elastic Load Balancer), you will need to use the nginx `realip` module (already installed) to extract the client's IP from the HTTP request headers. Please see the [nginx realip module configuration](http://nginx.org/en/docs/http/ngx_http_realip_module.html) for more details. This configuration can be added to a new config file and mounted in `/etc/nginx/conf.d/`.
|
||||
|
||||
@ -150,8 +157,11 @@ If you use fastcgi,you can set `VIRTUAL_ROOT=xxx` for your root directory
|
||||
|
||||
To set the default host for nginx use the env var `DEFAULT_HOST=foo.bar.com` for example
|
||||
|
||||
$ docker run -d -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 nginxproxy/nginx-proxy
|
||||
|
||||
nginx-proxy will then redirect all requests to a container where `VIRTUAL_HOST` is set to `DEFAULT_HOST`, if they don't match any (other) `VIRTUAL_HOST`. Using the example above requests without matching `VIRTUAL_HOST` will be redirected to a plain nginx instance after running the following command:
|
||||
|
||||
$ docker run -d -e VIRTUAL_HOST=foo.bar.com nginx
|
||||
|
||||
### Separate Containers
|
||||
|
||||
@ -168,7 +178,7 @@ $ curl -H "Host: whoami.local" localhost
|
||||
I'm 5b129ab83266
|
||||
```
|
||||
|
||||
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.
|
||||
To run nginx proxy as a separate container you'll need to have [nginx.tmpl](https://github.com/nginx-proxy/nginx-proxy/blob/main/nginx.tmpl) on your host system.
|
||||
|
||||
First start nginx with a volume:
|
||||
|
||||
@ -187,9 +197,9 @@ $ docker run --volumes-from nginx \
|
||||
Finally, start your containers with `VIRTUAL_HOST` environment variables.
|
||||
|
||||
$ docker run -e VIRTUAL_HOST=foo.bar.com ...
|
||||
### SSL Support using letsencrypt
|
||||
### SSL Support using an ACME CA
|
||||
|
||||
[letsencrypt-nginx-proxy-companion](https://github.com/JrCs/docker-letsencrypt-nginx-proxy-companion) is a lightweight companion container for the nginx-proxy. It allows the creation/renewal of Let's Encrypt certificates automatically.
|
||||
[acme-companion](https://github.com/nginx-proxy/acme-companion) is a lightweight companion container for the nginx-proxy. It allows the automated creation/renewal of SSL certificates using the ACME protocol.
|
||||
|
||||
Set `DHPARAM_GENERATION` environment variable to `false` to disabled Diffie-Hellman parameters completely. This will also ignore auto-generation made by `nginx-proxy`.
|
||||
The default value is `true`
|
||||
@ -202,7 +212,7 @@ certificates or optionally specifying a cert name (for SNI) as an environment va
|
||||
|
||||
To enable SSL:
|
||||
|
||||
$ 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
|
||||
$ 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 nginxproxy/nginx-proxy
|
||||
|
||||
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
|
||||
@ -226,7 +236,7 @@ at startup. Since it can take minutes to generate a new `dhparam.pem`, it is do
|
||||
background. Once generation is complete, the `dhparam.pem` is saved on a persistent volume and nginx
|
||||
is reloaded. This generation process only occurs the first time you start `nginx-proxy`.
|
||||
|
||||
> COMPATIBILITY WARNING: The default generated `dhparam.pem` key is 2048 bits for A+ security. Some
|
||||
> COMPATIBILITY WARNING: The default generated `dhparam.pem` key is 4096 bits for A+ security. Some
|
||||
> older clients (like Java 6 and 7) do not support DH keys with over 1024 bits. In order to support these
|
||||
> clients, you must either provide your own `dhparam.pem`, or tell `nginx-proxy` to generate a 1024-bit
|
||||
> key on startup by passing `-e DHPARAM_BITS=1024`.
|
||||
@ -234,7 +244,7 @@ is reloaded. This generation process only occurs the first time you start `ngin
|
||||
In the separate container setup, no pregenerated key will be available and neither the
|
||||
[jwilder/docker-gen](https://hub.docker.com/r/jwilder/docker-gen) image nor the offical
|
||||
[nginx](https://registry.hub.docker.com/_/nginx/) image will generate one. If you still want A+ security
|
||||
in a separate container setup, you'll have to generate a 2048 bits DH key file manually and mount it on the
|
||||
in a separate container setup, you'll have to generate a 2048 or 4096 bits DH key file manually and mount it on the
|
||||
nginx container, at `/etc/nginx/dhparam/dhparam.pem`.
|
||||
|
||||
#### Wildcard Certificates
|
||||
@ -276,7 +286,7 @@ and the [AWS ELB Security Policies](https://docs.aws.amazon.com/elasticloadbalan
|
||||
`AWS-TLS-1-2-2017-01`, `AWS-TLS-1-1-2017-01`, `AWS-2016-08`, `AWS-2015-05`, `AWS-2015-03` and `AWS-2015-02`.
|
||||
|
||||
Note that the `Mozilla-Old` policy should use a 1024 bits DH key for compatibility but this container generates
|
||||
a 2048 bits key. The [Diffie-Hellman Groups](#diffie-hellman-groups) section details different methods of bypassing
|
||||
a 4096 bits key. The [Diffie-Hellman Groups](#diffie-hellman-groups) section details different methods of bypassing
|
||||
this, either globally or per virtual-host.
|
||||
|
||||
The default behavior for the proxy when port 80 and 443 are exposed is as follows:
|
||||
@ -317,7 +327,7 @@ $ docker run -d -p 80:80 -p 443:443 \
|
||||
-v /path/to/htpasswd:/etc/nginx/htpasswd \
|
||||
-v /path/to/certs:/etc/nginx/certs \
|
||||
-v /var/run/docker.sock:/tmp/docker.sock:ro \
|
||||
jwilder/nginx-proxy
|
||||
nginxproxy/nginx-proxy
|
||||
```
|
||||
|
||||
You'll need apache2-utils on the machine where you plan to create the htpasswd file. Follow these [instructions](http://httpd.apache.org/docs/2.2/programs/htpasswd.html)
|
||||
@ -359,7 +369,7 @@ To add settings on a proxy-wide basis, add your configuration file under `/etc/n
|
||||
This can be done in a derived image by creating the file in a `RUN` command or by `COPY`ing the file into `conf.d`:
|
||||
|
||||
```Dockerfile
|
||||
FROM jwilder/nginx-proxy
|
||||
FROM nginxproxy/nginx-proxy
|
||||
RUN { \
|
||||
echo 'server_tokens off;'; \
|
||||
echo 'client_max_body_size 100m;'; \
|
||||
@ -368,7 +378,7 @@ RUN { \
|
||||
|
||||
Or it can be done by mounting in your custom configuration in your `docker run` command:
|
||||
|
||||
$ 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
|
||||
$ 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 nginxproxy/nginx-proxy
|
||||
|
||||
#### Per-VIRTUAL_HOST
|
||||
|
||||
@ -378,7 +388,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:
|
||||
|
||||
$ 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
|
||||
$ 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 nginxproxy/nginx-proxy
|
||||
$ { 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:
|
||||
@ -398,7 +408,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:
|
||||
|
||||
$ 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
|
||||
$ 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 nginxproxy/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
|
||||
|
||||
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:
|
||||
@ -417,26 +427,15 @@ Before submitting pull requests or issues, please check github to make sure an e
|
||||
|
||||
#### Running Tests Locally
|
||||
|
||||
To run tests, you need to prepare the docker image to test which must be tagged `jwilder/nginx-proxy:test`:
|
||||
|
||||
docker build -t jwilder/nginx-proxy:test . # build the Debian variant image
|
||||
|
||||
and call the [test/pytest.sh](test/pytest.sh) script.
|
||||
|
||||
Then build the Alpine variant of the image:
|
||||
|
||||
docker build -f Dockerfile.alpine -t jwilder/nginx-proxy:test . # build the Alpline variant image
|
||||
|
||||
and call the [test/pytest.sh](test/pytest.sh) script again.
|
||||
|
||||
|
||||
If your system has the `make` command, you can automate those tasks by calling:
|
||||
To run tests, you just need to run the command below:
|
||||
|
||||
make test
|
||||
|
||||
This commands run tests on two variants of the nginx-proxy docker image: Debian and Alpine.
|
||||
|
||||
You can run the tests for each of these images with their respective commands:
|
||||
|
||||
make test-debian
|
||||
make test-alpine
|
||||
|
||||
You can learn more about how the test suite works and how to write new tests in the [test/README.md](test/README.md) file.
|
||||
|
||||
### Need help?
|
||||
|
||||
If you have questions on how to use the image, please ask them on the [Q&A Group](https://groups.google.com/forum/#!forum/nginx-proxy)
|
||||
|
Reference in New Issue
Block a user