Getting Apache2 mod_dir redirect to http instead of https behind load balancer like CloudFlare

So I use Cloudflare a lot to protect my servers, terminate SSL, and cache stuff at scale.  One of the problems I run into is when the mod_dir module in my Apache thinks it is running http (which it is since Cloudflare is terminating my https) and Apache issues 301 redirects to http instead of https when you access a folder without a trailing slash.

The solution on ubuntu is to edit:

vi /etc/apache2/sites-available/000-default.conf

And add a ServerName with an https:// like this:


And run apachectl restart

This is a problem when running Tsugi behind a loadbalancer.  If you are using the tsugi-build approach – make sure to set the $APACHE_SERVER_NAME variable so it is automatically dropped in.