我花了很多时间,但没有找到任何解决方案。
我已经设置了Traefik和Nginx容器,这是我的docker-compose.yml

version: '3'
networks:
  proxy:
    external: true
  internal:
    external: false
services:
  mysql:
    image: 'mysql:5.7'
    environment:
      MYSQL_ROOT_PASSWORD: null
    networks:
      - internal
    labels:
      - traefik.enable=false
  adminer:
    image: 'adminer:latest'
    labels:
      - traefik.backend=adminer
      - 'traefik.frontend.rule=Host:db-admin.xxxx.xyz'
      - traefik.docker.network=proxy
      - traefik.port=8080
    networks:
      - internal
      - proxy
    depends_on:
      - mysql
  portainer:
    image: portainer/portainer
    networks:
      - internal
      - proxy
    labels:
      - "traefik.frontend.rule=Host:portainer.xxxx.xyz"
      - "traefik.port=9000"
      - "traefik.backend=portainer"
      - traefik.docker.network=proxy
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
    restart: unless-stopped
  Nginx-Pro:
    image: nginx:latest
    container_name: Nginx-Pro
    labels:
      - traefik.backend=Nginx-Pro
      - traefik.frontend.rule=Host:new.xxxx.fr
      - traefik.docker.network=proxy
      - "traefik.port=80"
      - "traefix.port=443"
      - "traefik.frontend.entryPoints=http"
    networks:
      - internal
      - proxy
    depends_on:
      - mysql
    volumes:
      - /var/www/nginx-pro/:/var/www/
      - /etc/nginx/nginx-pro/:/etc/nginx

因此,我还在/ etc / nginx / sites-enabled中的服务器上设置了虚拟主机
我也将日志添加到traefik conf,但是没有任何反应。

这是我的虚拟主机配置:
server {
        listen *:80;
        root /var/www/new.xxx.fr;

        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;

        server_name new.xxx.fr www.new.xxx.fr;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                                try_files $uri $uri/ /index.php?$args;
        }

        location ~ /\.ht {
                deny all;
        }
}

问题是我总是收到Traefik的Bad Gateway消息。

最佳答案

您需要添加traefik.frontend.passHostHeader,以便nginx可以将Host header 与server_name匹配。

但是由于此nginx仅适用于您已经与traefik.frontend.rule=Host:new.xxxx.fr匹配的一个域,因此您也可以将server_name保留在nginx vhost配置之外,并使用默认配置。

还要删除"traefix.port=443",因为您仅在traefik和nginx之间使用http,而您想要的是"traefik.frontend.entryPoints=http,https",也可以添加"traefik.frontend.headers.SSLRedirect=true"以始终将http重定向到https。

关于docker - Traefik与Nginx容器,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48901273/

10-16 10:42