让我们使用 traefik 加密配置
大家晚上好,
我在为 trafik docker 容器配置 https 连接时遇到问题。 使用以下配置访问 http://example.com 。但是,如果我取消注释 app
容器的最后两行,则会收到两个不同的错误
http://example .com ->找不到 404 页面
https://example.com ->无法访问该网站。 mydomain.com 拒绝连接。
请参阅下面的所有信息。有什么想法我在这里做错了吗?
docker-compose.yml:
proxy:
container_name: proxy
image: traefik:v2.6
ports:
- "80:80"
- "443:433"
- "8080:8080"
volumes:
- "./traefik.toml:/etc/traefik/traefik.toml"
- /var/run/docker.sock:/var/run/docker.sock
- /etc/letsencrypt:/letsencrypt
# PHP/Apache container
app:
container_name: php-node
image: projectx/php-node
build:
context: .
dockerfile: ./docker/php-node/Dockerfile
restart: always
labels:
- "traefik.enable=true"
- "traefik.http.routers.app.rule=Host(`example.com`)"
# - "traefik.http.routers.app.entrypoints=websecure"
# - "traefik.http.routers.app.tls.certresolver=letsencrypt"
traefik.toml:
[log]
level = "DEBUG"
[entryPoints]
[entryPoints.web]
address = ":80"
[entryPoints.websecure]
address = ":443"
[certificatesResolvers.letsencrypt.acme]
email = "[email protected]"
storage = "/letsencrypt/acme.json"
[certificatesResolvers.letsencrypt.acme.tlsChallenge]
日志(最后两行未注释):
time="2022-02-28T18:58:36Z" level=debug msg="Adding certificate for domain(s) example.com"
time="2022-02-28T18:58:36Z" level=debug msg="child http://xxx.xxx.xxx.x:80 now UP"
time="2022-02-28T18:58:36Z" level=debug msg="Propagating new UP status"
time="2022-02-28T18:58:36Z" level=debug msg="Creating middleware" middlewareType=Recovery entryPointName=web middlewareName=traefik-internal-recovery
time="2022-02-28T18:58:36Z" level=debug msg="Creating middleware" middlewareName=traefik-internal-recovery entryPointName=websecure middlewareType=Recovery
time="2022-02-28T18:58:36Z" level=debug msg="Creating middleware" entryPointName=websecure routerName=app@docker serviceName=app-examplecom middlewareName=pipelining middlewareType=Pipelining
time="2022-02-28T18:58:36Z" level=debug msg="Creating load-balancer" serviceName=app-examplecom entryPointName=websecure routerName=app@docker
time="2022-02-28T18:58:36Z" level=debug msg="Creating server 0 http://xxx.xxx.xxx.x:80" routerName=app@docker serverName=0 serviceName=app-examplecom entryPointName=websecure
time="2022-02-28T18:58:36Z" level=debug msg="child http://xxx.xxx.xxx.x:80 now UP"
time="2022-02-28T18:58:36Z" level=debug msg="Propagating new UP status"
time="2022-02-28T18:58:36Z" level=debug msg="Added outgoing tracing middleware app-examplecom" middlewareName=tracing entryPointName=websecure routerName=app@docker middlewareType=TracingForwarder
time="2022-02-28T18:58:36Z" level=debug msg="Creating middleware" middlewareName=traefik-internal-recovery entryPointName=websecure middlewareType=Recovery
time="2022-02-28T18:58:36Z" level=debug msg="Adding route for example.com with TLS options default" entryPointName=websecure
time="2022-02-28T18:58:36Z" level=debug msg="Try to challenge certificate for domain [example.com] found in HostSNI rule" routerName=app@docker rule="Host(`example.com`)" providerName=letsencrypt.acme ACME CA="https://acme-v02.api.letsencrypt.org/directory"
time="2022-02-28T18:58:36Z" level=debug msg="Looking for provided certificate(s) to validate [\"example.com\"]..." ACME CA="https://acme-v02.api.letsencrypt.org/directory" routerName=app@docker rule="Host(`example.com`)" providerName=letsencrypt.acme
time="2022-02-28T18:58:36Z" level=debug msg="No ACME certificate generation required for domains [\"example.com\"]." rule="Host(`example.com`)" providerName=letsencrypt.acme ACME CA="https://acme-v02.api.letsencrypt.org/directory" routerName=app@docker
Good evening guys,
I having trouble with configuring a https connection for my trafik docker container.
Accessing http://example.com is working with the following configuration. But if I uncomment the last two lines of my app
container, I get two different errors
http://example.com -> 404 page not found
https://example.com -> This site can't be reached. mydomain.com refused to connect.
See all information below. Any ideas what I am doing wrong here ?
docker-compose.yml:
proxy:
container_name: proxy
image: traefik:v2.6
ports:
- "80:80"
- "443:433"
- "8080:8080"
volumes:
- "./traefik.toml:/etc/traefik/traefik.toml"
- /var/run/docker.sock:/var/run/docker.sock
- /etc/letsencrypt:/letsencrypt
# PHP/Apache container
app:
container_name: php-node
image: projectx/php-node
build:
context: .
dockerfile: ./docker/php-node/Dockerfile
restart: always
labels:
- "traefik.enable=true"
- "traefik.http.routers.app.rule=Host(`example.com`)"
# - "traefik.http.routers.app.entrypoints=websecure"
# - "traefik.http.routers.app.tls.certresolver=letsencrypt"
traefik.toml:
[log]
level = "DEBUG"
[entryPoints]
[entryPoints.web]
address = ":80"
[entryPoints.websecure]
address = ":443"
[certificatesResolvers.letsencrypt.acme]
email = "[email protected]"
storage = "/letsencrypt/acme.json"
[certificatesResolvers.letsencrypt.acme.tlsChallenge]
Logs (with last two lines uncommented):
time="2022-02-28T18:58:36Z" level=debug msg="Adding certificate for domain(s) example.com"
time="2022-02-28T18:58:36Z" level=debug msg="child http://xxx.xxx.xxx.x:80 now UP"
time="2022-02-28T18:58:36Z" level=debug msg="Propagating new UP status"
time="2022-02-28T18:58:36Z" level=debug msg="Creating middleware" middlewareType=Recovery entryPointName=web middlewareName=traefik-internal-recovery
time="2022-02-28T18:58:36Z" level=debug msg="Creating middleware" middlewareName=traefik-internal-recovery entryPointName=websecure middlewareType=Recovery
time="2022-02-28T18:58:36Z" level=debug msg="Creating middleware" entryPointName=websecure routerName=app@docker serviceName=app-examplecom middlewareName=pipelining middlewareType=Pipelining
time="2022-02-28T18:58:36Z" level=debug msg="Creating load-balancer" serviceName=app-examplecom entryPointName=websecure routerName=app@docker
time="2022-02-28T18:58:36Z" level=debug msg="Creating server 0 http://xxx.xxx.xxx.x:80" routerName=app@docker serverName=0 serviceName=app-examplecom entryPointName=websecure
time="2022-02-28T18:58:36Z" level=debug msg="child http://xxx.xxx.xxx.x:80 now UP"
time="2022-02-28T18:58:36Z" level=debug msg="Propagating new UP status"
time="2022-02-28T18:58:36Z" level=debug msg="Added outgoing tracing middleware app-examplecom" middlewareName=tracing entryPointName=websecure routerName=app@docker middlewareType=TracingForwarder
time="2022-02-28T18:58:36Z" level=debug msg="Creating middleware" middlewareName=traefik-internal-recovery entryPointName=websecure middlewareType=Recovery
time="2022-02-28T18:58:36Z" level=debug msg="Adding route for example.com with TLS options default" entryPointName=websecure
time="2022-02-28T18:58:36Z" level=debug msg="Try to challenge certificate for domain [example.com] found in HostSNI rule" routerName=app@docker rule="Host(`example.com`)" providerName=letsencrypt.acme ACME CA="https://acme-v02.api.letsencrypt.org/directory"
time="2022-02-28T18:58:36Z" level=debug msg="Looking for provided certificate(s) to validate [\"example.com\"]..." ACME CA="https://acme-v02.api.letsencrypt.org/directory" routerName=app@docker rule="Host(`example.com`)" providerName=letsencrypt.acme
time="2022-02-28T18:58:36Z" level=debug msg="No ACME certificate generation required for domains [\"example.com\"]." rule="Host(`example.com`)" providerName=letsencrypt.acme ACME CA="https://acme-v02.api.letsencrypt.org/directory" routerName=app@docker
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论