1
0
mirror of https://github.com/nginx-proxy/nginx-proxy synced 2024-11-08 15:59:17 +01:00
Automated nginx proxy for Docker containers using docker-gen
Go to file
2024-02-22 05:59:51 -07:00
.github Add s390x support 2024-02-01 14:42:15 +08:00
app refactor: move nginx daemon off to procfile 2023-12-25 19:16:10 +01:00
docs highlight variables similar to other in readme 2024-02-19 12:21:02 +01:00
test Merge pull request #2399 from nginx-proxy/dependabot/pip/test/requirements/pytest-8.0.1 2024-02-21 17:55:46 +01:00
.dockerignore chore: include license into the Docker images 2022-03-09 12:05:56 +01:00
.gitignore Modified tests to include dhparams 2017-03-07 14:04:44 -05:00
docker-compose-separate-containers.yml ci: ensure all compose files are valid compose v2 + formatting 2023-12-12 21:56:27 +01:00
docker-compose.yml docs: add comment about host network to compose example 2024-02-22 05:59:51 -07:00
Dockerfile.alpine build: bump nginx from 1.25.3 to 1.25.4 2024-02-16 04:25:16 +00:00
Dockerfile.debian build: bump nginx from 1.25.3 to 1.25.4 2024-02-16 04:25:16 +00:00
LICENSE docs: update maintainers list on license 2022-01-11 19:46:42 +01:00
Makefile ci: use build matrix rather than separate jobs 2023-12-19 18:39:20 +01:00
network_internal.conf fix: Move NETWORK_ACCESS to location block 2022-02-24 15:08:18 +01:00
nginx.tmpl prevent double slash 2024-02-19 12:23:19 +01:00
README.md docs: update nginx badge 2024-02-18 10:08:23 +01:00

Test GitHub release nginx 1.25.4 Docker Image Size Docker stars Docker pulls

nginx-proxy sets up a container running nginx and docker-gen. docker-gen generates reverse proxy configs for nginx and reloads nginx when containers are started and stopped.

See Automated Nginx Reverse Proxy for Docker for why you might want to use this.

Usage

To run it:

docker run --detach \
    --name nginx-proxy \
    --publish 80:80 \
    --volume /var/run/docker.sock:/tmp/docker.sock:ro \
    nginxproxy/nginx-proxy:1.4

Then start any containers (here an nginx container) you want proxied with an env var VIRTUAL_HOST=subdomain.yourdomain.com

docker run --detach \
    --name your-proxied-app \
    --env VIRTUAL_HOST=foo.bar.com \
    nginx

Provided your DNS is setup to resolve foo.bar.com to the host running nginx-proxy, a request to http://foo.bar.com will then be routed to a container with the VIRTUAL_HOST env var set to foo.bar.com (in this case, the your-proxied-app container).

The containers being proxied must :

  • expose the port to be proxied, either by using the EXPOSE directive in their Dockerfile or by using the --expose flag to docker run or docker create.
  • share at least one Docker network with the nginx-proxy container: 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.

Note: providing a port number in VIRTUAL_HOST isn't suported, please see virtual ports or custom external HTTP/HTTPS ports depending on what you want to achieve.

Image variants

The nginx-proxy images are available in two flavors.

Debian based version

This image is based on the nginx:mainline image, itself based on the debian slim image.

docker pull nginxproxy/nginx-proxy:1.4

Alpine based version (-alpine suffix)

This image is based on the nginx:alpine image.

docker pull nginxproxy/nginx-proxy:1.4-alpine

⚠️ a note on latest and alpine:

It is not recommended to use the latest (nginxproxy/nginx-proxy, nginxproxy/nginx-proxy:latest) or alpine (nginxproxy/nginx-proxy:alpine) tag for production setups.

Those tags points to the latest commit in the main branch. They do not carry any promise of stability, and using them will probably put your nginx-proxy setup at risk of experiencing uncontrolled updates to non backward compatible versions (or versions with breaking changes). You should always specify the version you want to use explicitly to ensure your setup doesn't break when the image is updated.

Additional documentation

Please check the docs section.