我花了很多时间在上面,我没有找到任何解决方案。 我已经设置了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中的服务器上设置了vhost 我还将日志添加到traefik conf,但没有任何内容。
这是我的vhost配置:
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
消息。
答案 0 :(得分:0)
您需要添加traefik.frontend.passHostHeader
,以便nginx可以将Host
标头与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。