It was caused by CloudFlare https (which doesn't set the $_SERVER['HTTPS']$_SERVER['HTTPS']
variable), I solved it by forcing:
$_SERVER['HTTPS'] = 'on';
in the webserver configuration. After doing so I could also disable the "CloudFlare Flexible SSL" pluginCloudFlare Flexible SSL plugin, and get a little performance gain.