问题描述
我已经阅读了文档,但我不知道如何配置 Traefik v2 以在不涉及 Docker 的情况下将 Nginx 替换为网站(虚拟主机)的反向代理.理想情况下,我们也会对 https 进行加密.
I have read the documentation but I can not figure out how to configure Traefik v2 to replace Nginx as a reverse proxy for web sites (virtual hosts) without involving Docker. Ideally there would be let'sencrypt https as well.
我有一个在 http://127.0.0.1:4000 上运行的服务,我想对其进行反向代理来自 http://myhost.com:80
I have a service running at http://127.0.0.1:4000 which I would like to reverse proxy to from http://myhost.com:80
这是我到目前为止提出的配置:
This is the configuration i've come up with so far:
[Global]
checkNewVersion = true
[log]
level = "DEBUG"
filePath = "log-file.log"
[accessLog]
filePath = "log-access.log"
bufferingSize = 100
[entrypoints]
[entrypoints.http]
address = ":80"
[http]
[http.routers]
[http.routers.my-router]
rule = "Host(`www.myhost.com`)"
service = "http"
entrypoint=["http"]
[http.services]
[http.services.http.loadbalancer]
[[http.services.http.loadbalancer.servers]]
url = "http://127.0.0.1:4000"
推荐答案
我想通了,首先要注意的是,在 traefik v2 中有两种类型的配置,静态和动态.所以我创建了两个文件,traefik.toml 和 traefik-dynamic.toml.
I figured it out,the first part to note is that in traefik v2 there are two types of configuration, static and dynamic. So I created two files, traefik.toml and traefik-dynamic.toml.
traefik.toml 的内容:
contents of traefik.toml:
[log]
level = "DEBUG"
filePath = "log-file.log"
[accessLog]
filePath = "log-access.log"
bufferingSize = 100
[providers]
[providers.file]
filename = "traefik-dynamic.toml"
[api]
dashboard = true
debug = true
[entryPoints]
[entryPoints.web]
address = ":80"
[entryPoints.web-secure]
address = ":443"
[entryPoints.dashboard]
address = ":8080"
[certificatesResolvers.sample.acme]
email = "[email protected]"
storage = "acme.json"
[certificatesResolvers.sample.acme.httpChallenge]
# used during the challenge
entryPoint = "web"
traefik-dynamic.toml:
traefik-dynamic.toml:
[http]
# Redirect to https
[http.middlewares]
[http.middlewares.test-redirectscheme.redirectScheme]
scheme = "https"
[http.routers]
[http.routers.my-router]
rule = "Host(`www.example.com`)"
service = "phx"
entryPoints = ["web-secure"]
[http.routers.my-router.tls]
certResolver = "sample"
[http.services]
[http.services.phx.loadbalancer]
[[http.services.phx.loadbalancer.servers]]
url = "http://127.0.0.1:4000"
这篇关于Traefik v2 作为没有 docker 的反向代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!