reverse-proxy - Traefik v2 作为没有 docker 的反向代理
问题描述
我已经阅读了文档,但我不知道如何在不涉及 Docker 的情况下配置 Traefik v2 以替换 Nginx 作为网站(虚拟主机)的反向代理。理想情况下也会有 let'sencrypt https。
我有一个在http://127.0.0.1:4000运行的服务,我想从http://myhost.com:80反向代理
这是我到目前为止提出的配置:
[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。
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 = "myemail@example.com"
storage = "acme.json"
[certificatesResolvers.sample.acme.httpChallenge]
# used during the challenge
entryPoint = "web"
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"
推荐阅读
- php - PHP从内存中的curl调整图像大小
- alfresco - Alfresco:如何使用“lucensearch”搜索文件的 mimeType
- vue.js - Vue v-for 更新太慢了
- php - 在 PHP 文件中循环
- google-api - 我可以使用 GoogleDrive 中的默认文件类型图标吗?
- java - java net.sf.jasperreports.engine.JRRuntimeException: java.io.IOException: 系统找不到指定的路径
- python - 如何将分类变量中的 1 值重命名为列的标题?
- security - 如何将 CSRF 令牌从服务器传递到客户端?
- c++ - 用非原子读取排序原子读取
- mysql - Mysql Views 问题(重复)