【问题标题】:Traefik proxy ip authTraefik 代理 ip 验证
【发布时间】:2019-03-29 14:02:20
【问题描述】:

我在 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 时出现 Bad Host 错误,并且标头中的 IP 是我服务器的 ip 而不是我的真实 ip。 P.S Docker 在 swarm 模式下,但是 nginx 和 traefik 使用本地 docker-compose 构建

【问题讨论】:

    标签: docker docker-compose docker-swarm traefik


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-10
      • 1970-01-01
      • 1970-01-01
      • 2012-01-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多