Is there a reverse proxy in use? If so you may need $CFG->reverseproxy = true in config.php. There's information about this in the sample config-dist.php:
// Enable when setting up advanced reverse proxy load balancing configurations,
// it may be also necessary to enable this when using port forwarding.
$CFG->reverseproxy = true;