简体   繁体   English

traefik不遵守前端规则

[英]traefik not respecting frontend rule

I am trying to deploy multiple apps on my docker host and have traefik route traffic based on hostnames to the different apps 我试图在我的Docker主机上部署多个应用程序,并让traefik根据主机名将流量路由到不同的应用程序

I am using docker-compose for all my docker containers 我正在对所有Docker容器使用docker-compose

Here is my traeffik.yaml file 这是我的traeffik.yaml文件

version: '3.5'

services:
  traefik:
    image: traefik
    container_name: traefik
    command: --api --docker
    networks:
      - traefik_network
    ports:
      - "80:80"
      - "8080:8080"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

networks:
  traefik_network:
     name: traefik_network

here is my wpapp1.yaml file 这是我的wpapp1.yaml文件

version: '3.5'

services:
   mysql:
     image: mysql:5.7
     volumes:
       - wpapp1_mysql:/var/lib/mysql
     restart: always
     container_name: wpapp1_mysql
     networks:
       - traefik_network
     environment:
       MYSQL_ROOT_PASSWORD: wpapp1
       MYSQL_DATABASE: wpapp1
       MYSQL_USER: wpapp1
       MYSQL_PASSWORD: wpapp1
   wordpress:
     depends_on:
       - mysql
     image: wordpress:latest
     volumes:
       - wpapp1_wordpress:/var/www/html
     restart: always
     container_name: wpapp1_wordpress
     networks:
       - traefik_network
     labels:
      - "traefik.frontend.rule=Host:wpapp1.example.com"
      - "traefik.port=80"
      - "traefik.docker.network=traefik_network"
     environment:
       WORDPRESS_DB_HOST: mysql:3306
       WORDPRESS_DB_USER: wpapp1
       WORDPRESS_DB_PASSWORD: wpapp1
volumes:
    wpapp1_mysql:
      name: wpapp1_mysql
    wpapp1_wordpress:
      name: wpapp1_wordpress
networks:
    traefik_network:
      external:
         name: traefik_network

and here is my wpapp2.yaml file 这是我的wpapp2.yaml文件

version: '3.5'

services:
   mysql:
     image: mysql:5.7
     volumes:
       - wpapp2_mysql:/var/lib/mysql
     restart: always
     container_name: wpapp2_mysql
     networks:
       - traefik_network
     environment:
       MYSQL_ROOT_PASSWORD: wpapp2
       MYSQL_DATABASE: wpapp2
       MYSQL_USER: wpapp2
       MYSQL_PASSWORD: wpapp2
   wordpress:
     depends_on:
       - mysql
     image: wordpress:latest
     volumes:
       - wpapp2_wordpress:/var/www/html
     restart: always
     container_name: wpapp2_wordpress
     networks:
       - traefik_network
     labels:
      - "traefik.frontend.rule=Host:wpapp2.example.com"
      - "traefik.port=80"
      - "traefik.docker.network=traefik_network"
     environment:
       WORDPRESS_DB_HOST: mysql:3306
       WORDPRESS_DB_USER: wpapp2
       WORDPRESS_DB_PASSWORD: wpapp2
volumes:
    wpapp2_mysql:
      name: wpapp2_mysql
    wpapp2_wordpress:
      name: wpapp2_wordpress
networks:
    traefik_network:
      external:
         name: traefik_network

So now i expect traefik to route based on the hostnames wpapp1.example.com and wpapp2.example.com BUT traefik is loadbalancing traffic!!! 所以现在我期待traefik路由基于主机名wpapp1.example.comwpapp2.example.com但traefik的负载均衡流量!

So when i go to http:/wpapp1.example.com , traefik is loadbalancing it between the two apps and same for the other hostnames. 因此,当我转到http:/wpapp1.example.com ,traefik会在两个应用程序之间进行负载http:/wpapp1.example.com ,其他主机名也是如此。 Now sure what is going on here since i specifically add the traefik.frontend.rule 现在确定这里发生了什么,因为我专门添加了traefik.frontend.rule

I mean how in the hell is that happening? 我的意思是这到底是怎么回事? I have spent hours to figure what is going on and before i go insane i decided to some here to get some help on what is going on here. 我花了几个小时弄清楚发生了什么事,在发疯之前,我决定在这里寻求一些帮助。

Put your database on a different network. 将数据库放在其他网络上。 Otherwise WordPress will RR load balance to the two mysql instances in the same docker network (that's the expected behavior when you have two containers with the same alias on the same network). 否则,WordPress将RR负载均衡到同一docker网络中的两个mysql实例(当您在同一网络上有两个具有相同别名的容器时,这是预期的行为)。 You can do that with the default network: 您可以使用默认网络来做到这一点:

version: '3.5'

services:
   mysql:
     image: mysql:5.7
     volumes:
       - mysql:/var/lib/mysql
     restart: unless-stopped
     networks:
       - db
     environment:
       MYSQL_ROOT_PASSWORD: wpapp
       MYSQL_DATABASE: wpapp
       MYSQL_USER: wpapp
       MYSQL_PASSWORD: wpapp
   wordpress:
     depends_on:
       - mysql
     image: wordpress:latest
     volumes:
       - wordpress:/var/www/html
     restart: unless-stopped
     networks:
       - traefik
       - db
     labels:
      - "traefik.frontend.rule=Host:wpapp1.example.com"
      - "traefik.port=80"
      - "traefik.docker.network=traefik_network"
     environment:
       WORDPRESS_DB_HOST: mysql:3306
       WORDPRESS_DB_USER: wpapp
       WORDPRESS_DB_PASSWORD: wpapp
volumes:
    mysql:
    wordpress:
networks:
    db:
    traefik:
      external:
         name: traefik_network

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在traefik配置中使用通配符作为前端规则 - Use wildcard for frontend rule in traefik configuration Traefik / Docker:使用端口作为前端规则(而不是路径或子域) - Traefik/Docker: Using ports as a frontend rule (rather than paths or subdomains) Docker Swarm + Traefik:通过前端规则公开Traefik GUI; 服务/容器端口重定向 - Docker Swarm + Traefik: Expose Traefik GUI through frontend rule; Service / Container port redirection Traefik:前端未定义的后端 - Traefik: Undefined backend for frontend 使用 nuxt static 应用程序到前端容器的 traefik 代理 - traefik proxy to frontend container with nuxt static app 将Traefik前端重定向替换与PathPrefixStrip结合使用 - Combining Traefik frontend redirect replacement with PathPrefixStrip Traefik 规则需要子域的解决方案 - Traefik rule need solution for sub domain 带有docker后端的traefik反向代理 - 在traefik的配置文件中配置前端规则而不是通过容器标签 - traefik reverse-proxy with docker backend - configure frontend rules in traefik's config file and not via container label 如何将 Gitlab CI 变量作为 Traefik traefik.http.routers.container_name.rule 标签值传递 - how to pass Gitlab CI variable as a Traefik traefik.http.routers.container_name.rule label value Traefik 2.0 - 路径路由器规则不适用于 docker 标签 - Traefik 2.0 - Path router rule not working with docker labels
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM