Ensure $CFG->wwwroot
matches the URL used in the browser. If your site is HTTPS this must be 'https://...'.
If the site is HTTPS but the Moodle web server is serving over HTTP (not HTTPS) you may need $CFG->sslproxy = true;
in config.php
. Or try $CFG->reverseproxy = true;
if you're using a reverse proxy.