Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

nginx - Is it possible to have (dynamic) multiple redirection to 1 container?

I'm currently using nginx-proxy & docker-letsencrypt-nginx-proxy-companion to have redirection to a web-app containerized and deployed using docker-swarm.
So when I calling https://www.my-app.my-domain.com, I'm displaying on the browser my web-app. This web-app is a multi-tenant app, and I would like to use sub-domain to give access to each client.
Here is what it means:

  • tenant A (code aaa) will call https://www.aaa.my-app.my-domain.com
  • tenant B (code bbb) will call https://www.bbb.my-app.my-domain.com

The web-app will handle (either by parsing the hostname or by checking an header) which tenant it is, and so display relative data only.

1st question: How to to this ?
2th question: Can we also add a rule to add an header (like X-Tenant=aaa) on the call ?

Here is a simple docker-stack file showing the configuration I use:

version: '3.7'

services:

  nginx-proxy:
    image: jwilder/nginx-proxy:alpine-0.7.0
    deploy:
      mode: replicated
      replicas: 1
    ports:
      - 80:80
      - 443:443
    networks:
      - my-network
    volumes:
      - dhparam:/etc/nginx/dhparam
      - certs:/etc/nginx/certs:ro
      - vhost:/etc/nginx/vhost.d
      - html:/usr/share/nginx/html
      - /var/run/docker.sock:/tmp/docker.sock:ro
    labels:
      - com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy

  nginx-proxy-letsencrypt:
    image: jrcs/letsencrypt-nginx-proxy-companion:v1.13
    deploy:
      mode: replicated
      replicas: 1
    depends_on:
      - nginx-proxy
    networks:
      - my-network
    volumes:
      - certs:/etc/nginx/certs:rw
      - vhost:/etc/nginx/vhost.d
      - html:/usr/share/nginx/html
      - /var/run/docker.sock:/var/run/docker.sock:ro
    environment:
      DEFAULT_EMAIL: [email protected]

  my-app:
    image: my/app:X.Y.Z
    deploy:
      mode: replicated
      replicas: 1
    networks:
      - my-network
    environment:
      VIRTUAL_HOST: www.my-app.my-domain.com
      LETSENCRYPT_HOST: www.my-app.my-domain.com

volumes:
  dhparam:
  vhost:
  html:
  certs:

networks:
  my-network:
    external: true
    name: my-network
question from:https://stackoverflow.com/questions/65860826/is-it-possible-to-have-dynamic-multiple-redirection-to-1-container

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...