[英]Use nginx on route and traefik for subdomain
How would the docker-compose file and nginx configuration look if I want to use traefik to proxy requests for my subdomains and use nginx on my root. 如果我想使用traefik代理对子域的请求并在根目录上使用nginx,则docker-compose文件和nginx的配置将如何显示。
So, i want to serve up some static files to: domain.com using nginx but i want traefik to handle traffic to: app.domain.com, app2.domain.com 因此,我想使用nginx将某些静态文件提供给:domain.com,但我希望traefik处理以下流量:app.domain.com,app2.domain.com
here is what i have in my composer file.... 这是我在作曲家文件中拥有的...
version: '3'
networks:
proxy:
external: true
internal:
external: false
services:
traefik:
image: traefik:alpine
ports:
- "8080:8080"
- "80:80"
- "443:443"
restart: always
labels:
- logLevel="DEBUG"
- "traefik.backend=monitor"
- "traefik.frontend.rule=Host:monitor.domain.com"
- "traefik.port=8080"
- "traefik.frontend.entryPoints=http,https"
- "traefik.enable=true"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
- "./traefik.toml:/traefik.toml"
- "./acme.json:/acme.json"
expose:
- "8080"
networks:
- internal
- proxy
custom-badge:
image: app
environment:
PORT: 3000
ports:
- "3000:3000"
labels:
- traefik.enabled=true
- traefik.backend=custom-badge
- traefik.frontend.rule=Host:app.domain.com
- traefik.docker.network=proxy
- traefik.port=3000
networks:
- internal
- proxy
server:
image: nginx:alpine
ports:
- "80:80"
labels:
- traefik.enabled=true
- traefik.backend=
- traefik.frontend.rule=domain.com
- traefik.docker.network=proxy
- traefik.port=80
volumes:
- "./apps/root:/etc/nginx/html:ro"
- "./nginx.conf:/etc/nginx/nginx.conf:ro"
environment:
- NGINX_HOST=domain.com
- NGINX_PORT=80
command: [nginx-debug, '-g', 'daemon off;']
depends_on:
- traefik
and my nginx.conf 和我的nginx.conf
http {
server {
listen 80;
server_name domain.com www.domain.com;
location / {
proxy_pass domain.com:80/;
}
}
}
Im getting port conflict errors, what am i doing wrong? 我收到端口冲突错误,我在做什么错?
You cannot have two services - traefik and nginx use same host port. 您不能有两个服务-traefik和nginx使用相同的主机端口。
You must have only one service listening on 80 port. 您只能在80端口上侦听一项服务。
I would suggest configuring traefik to proxy all communication and in case of lack of subdomain forward to nginx - and what I can see - you did. 我建议配置traefik以代理所有通信,并在缺少子域的情况下转发给nginx-以及我所看到的-您做到了。
To fix your error simply remove port section from server (nginx) service definition. 要解决您的错误,只需从服务器(nginx)服务定义中删除端口部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.