你需要使用
traefik.port
定义后端端口。对你来说应该是
traefik.port=9000
.
80
,因为您希望它在另一个端口上侦听,所以需要为其定义地址
entryPoints
--entryPoints='Name:http Address::8000'
,在本例中,它将在端口上侦听
8000
.
我给你举一个使用docker的例子,然后你可以用marathon做一个比较。
运行Traefik在端口上侦听
:
docker service create \
--name traefik \
--mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock \
--network traefik-net \
--publish 8080:8080 \
--publish 8000:8000 \
traefik \
--entryPoints="Name:http Address::8000" \
--defaultentrypoints="http" \
--checknewversion=false \
--docker \
--docker.swarmmode \
--docker.domain=mydomain.com \
--docker.watch \
--docker.exposedbydefault=false \
--web \
--loglevel=DEBUG
后端侦听端口
9000
docker service create \
--name myweb \
--mount type=bind,source=$PWD/httpd.conf,target=/usr/local/apache2/conf/httpd.conf \
--label traefik.port=9000 \
--label traefik.enable=true \
--network traefik-net \
httpd
测试它,检查Traefik
api
:
$ curl -s "http://localhost:8080/api" | jq .
{
"docker": {
"backends": {
"backend-myweb": {
"servers": {
"server-myweb-1": {
"url": "http://10.0.0.5:9000",
"weight": 0
}
},
"loadBalancer": {
"method": "wrr"
}
}
},
"frontends": {
"frontend-Host-myweb-mydomain-com": {
"entryPoints": [
"http"
],
"backend": "backend-myweb",
"routes": {
"route-frontend-Host-myweb-mydomain-com": {
"rule": "Host:myweb.mydomain.com"
}
},
"passHostHeader": true,
"priority": 0,
"basicAuth": []
}
}
}
}
$ curl -H "Host: myweb.mydomain.com" "http://localhost:8000/"
<html><body><h1>It works!</h1></body></html>