0

I don't think it's anywhere here as I was looking for that a while, but forgive me if you find my question possible duplicate.

I have VPS server. All websites there run in docker containers with nginx / nginx-gen / nginx lets encrypt companion in the front.

I have one largest app there which will enable users to add their domains to point this app. I have to have it automated. My app will handle domains accordingly and that's not an issue.

The question is how to set up nginx to forward all requests for domains which are not handled by any other containers (so they are getting separate config blocks) to my app which is one of the containers.

Is there any way to do that?

Marek Urbanowicz
  • 12,659
  • 16
  • 62
  • 87
  • 1
    The `default_server` server block will match all domains that are not explicitly handled by another server block. See [this document](http://nginx.org/en/docs/http/server_names.html#miscellaneous_names) for details. – Richard Smith Jun 18 '17 at 19:01

1 Answers1

1

It's very simple to do:

docker-compose.yml

version: '2'
services:
  nginx-proxy:
    image: jwilder/nginx-proxy
    container_name: nginx-proxy
    ports:
      - "80:80"
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro
      - ./nginx.tmpl:/app/nginx.tmpl
    environment:
      - DEFAULT_HOST=whoami2.local

  whoami:
    image: jwilder/whoami
    environment:
      - VIRTUAL_HOST=whoami.local

  whoami2:
    image: jwilder/whoami
    environment:
      - VIRTUAL_HOST=whoami2.local

In this way everything that is not defined as domain within nginx will be redirected to whoami2 service.

I hope this change works for you

German
  • 1,449
  • 12
  • 13