无法在 AWS 负载均衡器后面从 http 重定向到 https

2024-01-07

我正在具有 rancher 后端的 AWS 实例上运行 traefik。我正在 AWS 负载均衡器处终止 SSL,并在端口 80 上与实例进行通信,该实例将 :80 流量转发到 traefik 容器。

所以负载均衡器目前有: https:443 ==> http:80 http:80 ==> http:80

这意味着,如果您输入https://example.com https://example.com,您将获得 SSL,并且如果您键入http://example.com http://example.com,你只得到一个普通的http连接。

我们的愿望是通过 http 302 自动重定向——它会重定向http://example.com http://example.com to https://example.com https://example.com.

到目前为止,我未成功的尝试如下:

** AWS 负载均衡器**

https:443 => http:80
http:80 => http:81

traefik.toml
------------
[entryPoints]
  [entryPoints.http]
  address = ":81"
     [entryPoints.http.redirect]
     regex = "^http://example.com/(.*)"
     replacement = "https://example.com/$1"
  address = ":80"

docker-compose.yml
------------------
API-Proxy:
  container_name: api-proxy
  image: traefik
  volumes:
  - "/var/run/docker.sock:/var/run/docker.sock"
  - "$PWD/traefik.toml:/etc/traefik/traefik.toml"
  command: "--web --rancher --docker.domain=rancher.localhost --logLevel=DEBUG"
  cpu_shares: 128
  restart: always
  ports:
  - 80:80/tcp
  - 81:81/tcp
  - 8100:8080/tcp

当我尝试通过端口 80 访问时,出现超时。 Traefik 日志似乎没有帮助。

这是一种愚蠢的做法吗?或者使用 Let's encrypt 在 traefik 容器中终止 SSL 是否更好?


在您的 Traefik 配置中尝试类似的操作。然后将 LB 上的端口 443 和 80 转发到 Traefik 上的端口 80。

[entryPoints]
  [entryPoints.http]
     address = ":80"
     [entryPoints.http.redirect]
     regex = "^http://(.*)"
     replacement = "https://$1"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法在 AWS 负载均衡器后面从 http 重定向到 https 的相关文章

随机推荐