如何让traefik从docker内部重定向到特定的非docker端口

编程入门 行业动态 更新时间:2024-10-25 08:22:45
本文介绍了如何让traefik从docker内部重定向到特定的非docker端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

首先,如果我没有使用正确的术语来问这个问题,我很抱歉,但我不适合现有的术语.

First of all I'm sorry if I'm not using the right terms to ask this question, but I'm not up to the terminology in place.

我在 docker 容器中运行 traefik 并使用 PathPrefix 选项提供一些服务,例如,www.myserver/wordpress 重定向到运行 wordpress 的 docker 容器.

I have traefik running in a docker container and serving some services with the PathPrefix option, for instance, www.myserver/wordpress redirects to a docker container running wordpress.

但是我如何让它重定向到 docker 容器之外呢?具体来说,我如何让 www.myserver 重定向到我机器中的端口 8080 以提供我在主机操作系统中运行的服务(而不是在 docker 容器中)?

But how do I get it to redirect to outside a docker container? Specifically, how do I get www.myserver to redirect to port 8080 in my machine to serve a service I have running there in the host OS (not in a docker container)?

这是我的traefik.toml:

logLevel = "DEBUG" defaultEntryPoints = ["http", "https"] [entryPoints] [entryPoints.http] address = ":80" compress = false [entryPoints.http.redirect] entryPoint = "https" [entryPoints.https] address = ":443" [entryPoints.https.tls] [acme] email = "mymail@mail" storage = "acme.json" entryPoint = "https" onHostRule = true #onDemand = true [[acme.domains]] main = "www.myserver" [web] address = ":8888" [docker] endpoint = "unix:///var/run/docker.sock" domain = "www.myserver" watch = true exposedbydefault = false

还有我的 docker-compose.yml 用于 traefik 容器:

And my docker-compose.yml for the traefik container:

version: "2" services: traefik: image: traefik network_mode: "host" ports: - "80:80" - "443:443" - "8888:8888" volumes: - /var/run/docker.sock:/var/run/docker.sock - ${SERVER_DIR}/AppData/traefik:/etc/traefik/ - ${PWD}/acme.json:/acme.json - ${PWD}/traefik.toml:/etc/traefik/traefik.toml - ${PWD}/servers.toml:/etc/traefik/servers.toml restart: never

推荐答案

我摸索着找到了答案.

在 traefik.toml 中添加:

################################################################ # File configuration backend ################################################################ # Enable file configuration backend # Optional [file] filename = "servers.toml" # Enable watch file changes watch = true

在 docker-compose.yml 中将 volumes: 更改为:

In docker-compose.yml change the volumes: to:

volumes: - /var/run/docker.sock:/var/run/docker.sock - ${SERVER_DIR}/AppData/traefik:/etc/traefik/ - ${PWD}/acme.json:/acme.json - ${PWD}/traefik.toml:/etc/traefik/traefik.toml - ${PWD}/servers.toml:/servers.toml

添加文件servers.toml:

loglevel = "ERROR" [backends] [backends.nasweb] [backends.nasweb.servers.nasweb] url = "192.168.1.11:8080" [frontends] [frontends.domain] backend = "nasweb" [frontends.domain.routes.domain] rule = "Host:www.myserver"

更多推荐

如何让traefik从docker内部重定向到特定的非docker端口

本文发布于:2023-11-14 09:08:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586802.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:端口   重定向   traefik   docker

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!