我的应用程序在 Windows 上使用 Visual Studio(技术上是 iisexpress)运行。我能够成功测试我的应用程序是否可以通过 http://localhost:5100 和 https://localhost:7254 访问(该证书是由 Visual Studio 自动创建的,仅用于开发/测试目的)。
以下是我使用 traefik 测试上述网站的脚本:
version: "3.7"
services:
proxy:
image: traefik:2.0
command:
- "--providers.file.filename=/etc/traefik/proxy-config.toml"
- "--entrypoints.http.address=:80"
- "--entrypoints.https.address=:443"
ports:
- "80:80"
- "443:443"
volumes:
- ./proxy-config.toml:/etc/traefik/proxy-config.toml:ro
proxy-config.toml 如下:
[serversTransport]
insecureSkipVerify = true
[api]
insecure = true
dashboard = true
debug = true
[http.routers]
[http.routers.app-website]
rule = "Host(`test.localhost`)"
service = "app-website-http"
entryPoints = ["http"]
[http.routers.app-website-https]
rule = "Host(`test.localhost`)"
service = "app-website-https"
entryPoints = ["https"]
[http.routers.app-website-https.tls]
certResolver = "tlsresolver"
[http.services]
[http.services.app-website-http.loadBalancer]
[[http.services.app-website-http.loadBalancer.servers]]
url = "http://host.docker.internal:5100"
[http.services.app-website-https.loadBalancer]
[[http.services.app-website-https.loadBalancer.servers]]
url = "https://host.docker.internal:7254"
[certificatesResolvers]
[certificatesResolvers.tlsresolver.acme]
email = "[email protected]"
storage = "./acme.json"
[certificatesResolvers.tlsresolver.acme.httpChallenge]
entryPoint = "http"
[certificatesResolvers.tlsresolver.acme.tlsChallenge]
我修改了hosts文件以将test.localhost重定向到127.0.0.1。上面的代码适用于“http”并且没有任何问题(即将 http://test.localhost 重定向到 http://localhost:5100 没有问题)。但是,“https”失败。它首先抛出证书错误(您的连接不是私有的),然后继续我遇到“内部服务器错误”。
我想利用 traefik 的“自动 ssl 证书创建”功能并确保重定向到我的 https://localhost:7254。简而言之,如果我浏览到 https://test.localhost,它必须重定向到 https://localhost:7254。
作为 traefik 的新手,我不确定如何使用上述脚本启用/检查 traefik 日志(或 traefik 仪表板)。感谢您的帮助!
如果您希望使用像 Let's Encrypt 这样的 ACME 证书提供商,您需要遵循 这些说明。请注意,要实现此功能,您需要使用可解析的主机名,即 DNS 中存在且可由 Let's Encrypted 证书颁发者解析的名称。
test.localhost
除了本地系统之外,无法从任何地方解析。