I am wondering if it is possible to configure the load balancer to send a redirect from port 80 to port 443.
A solution I would use is to use a simple service that has the only role to redirect everything arrives to 80 port. I map the 80 port f the load balancer to that service, and it should be done.
However, the optimal solution would be adding the configuration to HAProxy, something like:
A container that does redirects seems like a good idea for now. Doing it in haproxy would likely be another use case for #1871 unless we think this is a common enough feature to make it a specific API config option.
Thanks Vincent. I will update the issue you linked with my use case.
I think the main problem is, how do we access the cluster from the Internet? Do we place a Proxy in front of it, or we use Rancher’s load balancer? As for the current state I see problems for both scenarios.
If we expose Rancher’s load balancers externally I see these problems:
cannot configure redirects (such as 80 to 443)
cannot configure ssl certificates with the CLI (I could not set them through rancher-compose, only through UI, ticking the ssl box)
If I add a proxy in front of the cluster to handle the redirects and forward of requests, pointing to the load balancer I see the following problems:
I cannot automatically detect the host the Racnher’s load balancers is, and trigger config updates on host changes. I could add something like consul to fix this, but it looks overkill due to the fact I would just use Rancher to orchestrate my infrastructure.
Therefore my questions are?
do you guys plan to make Rancher’s load balancer suitable to work as an external proxy?
do you plan to include a distributed configuration (such as consul or etcd) so that changes in the cluster can be detected and actions can be triggered?
Managing SSL certificates on balancer so through compose is in the next release.
I’m not sure why you’re talking about proxying, if you just want all http requests to be 302ed to https you just need an almost 1-liner nginx or Apache image that serves redirects. Then point port 80 in the balancer to a service running that image, and 443 to your actual app service. Here’s an (old) example: https://github.com/jamessharp/docker-nginx-https-redirect
It is possible to get info about where the containers of a service are running from metadata though.
Before I spun up an instance of geldim/https-redirect:latest outside of my load balancer and told it to run on every host. This worked, though it was a bit hacky and opens 80 unnecessarily in some places.
Today I tried adding it into a load balancer with both 80 and 443 open (443 was only open previously.) I have a rule with no hostname set, port 80 open, redirecting to geldim/https-redirect:latest port 80. Every other rule has a hostname and port 443 set as the source.
If I hit, say, http://ci.thewordnerd.info, sometimes it shows the HTTP redirect, sometimes I get a 503. They’re hosted behind Cloudflare but I see this even when hitting the VM directly and setting the Host: header manually. All hosts seem to work if I hit them via https.
How can I provide additional information to help resolve this? Would you like my rancher-compose definition just as a reference, even though compose can’t spin up load balancers yet? Or should I get the haproxy.cfg from the balancer instance? Let me know.
I’ve pasted the content here to make it easier:
If you want to see the configuration of the load balancer, you will need to exec into the specific LB Agent container and look for the configuration file. You can use the UI and select Execute Shell on the container.
$ cat /etc/haproxy/haproxy.cfg
This file will provide all the configuration details of the load balancer.
nginx-https-redirect listens on port 80 only and the load balancer listening on 443 only. The redirect container will catch all http traffic and redirect to https traffic which will be picked up by load balancer.
Your LB should only listen to port 443. And you create another service using the docker-nginx-https-redirect that listens to port 80. The docker compose would look something like this:
to my custom HAproxy.cfg i either get a 503 if i have a other http:80 service rule active (pseudo) or connection denied if i have no other http/80 service role ( only https/443)
If you have multiple sites, some with ssl and other with regular http this has worked for me:
frontend 80
#redirect scheme https code 301 if !{ ssl_fc } (I kept this just for reference purposes)
redirect scheme https if { hdr(Host) -i [your.domain.com] } !{ ssl_fc }
That line redirects only the domains that have ssl enabled. Make sure that the load balancer has the correct 443 port set up to listen for requests and points to the correct container port.
Let me know if this works for you, otherwise I am sure we can solve the problem.