Traefik代理IP身份验证

时间:2019-03-29 14:02:20

标签: docker docker-compose docker-swarm traefik

我在docker-compose中有一个traefik:

 version: '3'
    networks:
      proxy:
        driver: bridge
    services:
      traefik:
        container_name: traefik
        image: traefik:v1.7.9
        command: --api --docker
        ports:
          - "80:80"
          - "443:443"
          - "8080:8080"
        volumes:
          - /var/run/docker.sock:/var/run/docker.sock
          - ./traefik.toml:/etc/traefik/traefik.toml
          - ./acme.json:/acme.json
         networks: 
          - proxy

在mydomain.com下也有nginx,我只允许我的IP连接到它:

nginx:
    build: ./nginx
    networks:
      - backend
      - traefik_proxy
    restart: always
    labels:
      traefik.enable: "true"
      traefik.port: "80"
      traefik.frontend.headers.allowedHosts: "1.2.3.4" # MyIp
      traefik.frontend.rule: "Host:mysite.com,www.mysite.com"

当我访问mysite.com时,出现主机错误错误,并且标头中的IP是服务器的IP,而不是我的真实IP。 P.S Docker处于集群模式,但是nginx和traefik使用本地docker-compose构建

1 个答案:

答案 0 :(得分:0)

解决方案是向nginx docker-compose添加以下指令:

traefik.frontend.whiteList.sourceRange: "1.2.3.4" # my Ip
traefik.frontend.passHostHeader: true
traefik.frontend.whiteList.useXForwardedFor: "true"