使用Traws在Aws Loadbalancer后面进行HTTPS重定向

Isp*_*ria 2 http-redirect docker docker-compose elastic-load-balancer traefik

我正在尝试将所有传入的Traefik从http重定向到https,用于从具有自定义端口的docker容器中提供服务的Web应用程序.

如果我构建这个docker compose文件,并缩放应用程序,一切都按预期工作.我能够请求应用程序的http和https,但我尝试完成只有https获取服务,http被重定向到https.

由于我使用的是Docker-Compose文件,因此我没有Traefik.toml,并试图在没有它的情况下完成此任务.

Docker撰写:

traefik:
  image: traefik:latest
  command:
   - "--api"
   - "--docker"
   - "--docker.domain=example.com"
   - "--logLevel=DEBUG"
   - "--docker.watch"
  labels:
    - "traefik.enable=true"
  ports:
    - "80:80"
    - "8080:8080"
    - "443:443"
  volumes:
    - /var/run/docker.sock:/var/run/docker.sock
    - /dev/null:/traefik.toml

application:
  image: application
  command: web
  tty: false
  stdin_open: true
  restart: always
  expose:
    - "8081"
  labels:
    - "traefik.backend=application"
    - "traefik.frontend.rule=HostRegexp:{subdomain:[a-z]+}.example.com"
    - "traefik.frontend.priority=1"
    - "traefik.enable=true"
  volumes:
    - /var/run/docker.sock:/var/run/docker.sock
Run Code Online (Sandbox Code Playgroud)

我尝试了应用程序容器的不同变体,例如:

- "traefik.frontend.entryPoints=http,https"
- "traefik.frontend.redirect.entryPoint=https"
- "traefik.frontend.headers.SSLRedirect=true"
Run Code Online (Sandbox Code Playgroud)

但我可以完成的最大化是使用SSLRedirect标签进行多次重定向响应,并且没有从traefik获得以下内容,并且http或https请求都没有正确转发.

 level=error msg="Recovered from panic in http handler: runtime error: invalid memory address or nil pointer dereference"
Run Code Online (Sandbox Code Playgroud)

任何人都可以把我推向正确的方向吗?

提前致谢 ;)

我在以下设置下运行

 user:~$ docker --version
 Docker version 1.13.1, build 092cba3

 user:~$ docker-compose --version
 docker-compose version 1.8.0
Run Code Online (Sandbox Code Playgroud)

Docker PS响应

IMAGE           COMMAND                 ... PORTS                                                              NAMES
application     "dotnet Web..."         ... 8081/tcp                                                           components_application_1
traefik:latest  "/traefik --api --..."  ... 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:8080->8080/tcp   components_traefik_1
Run Code Online (Sandbox Code Playgroud)

基础设施安装

 aws-elb => vpc => ec2...ecn 
                   traefik per instance, 
                   n applications per instance
Run Code Online (Sandbox Code Playgroud)

Isp*_*ria 6

经过深入研究,我自己找到了解决方案.

我添加后,问题是应用程序Container上缺少标签

- "traefik.frontend.headers.SSLProxyHeaders=X-Forwarded-Proto: https"
- "traefik.frontend.headers.SSLRedirect=true"
Run Code Online (Sandbox Code Playgroud)

在我的应用程序容器上,它就像一个带有清晰301重定向的魅力.

为什么需要标头,默认情况下,aws-elb接受https请求并使用HTTP(80)将其转发到连接的实例,在此过程中,elb将X-Forwarded-Proto: httpsHeader 添加到请求中.

由于traefik不知道它在elb后面运行,它会一遍又一遍地重定向.但是Header阻止了这种行为.