The $site_url is determined by the config.inc.php file. It is generated automatically from data sent by the server and stored by PHP in the $_SERVER array. This is stored in the MODx array config, which is how you can access it via [(site_url)] in your HTML and $modx->config[’site_url’] in snippet code.
$site_url= ((isset ($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') || $_SERVER['SERVER_PORT'] == $https_port) ? 'https://' : 'http://';
$site_url .= $_SERVER['HTTP_HOST'];
if ($_SERVER['SERVER_PORT'] != 80)
$site_url= str_replace(':' . $_SERVER['SERVER_PORT'], '', $site_url); // remove port from HTTP_HOST
$site_url .= ($_SERVER['SERVER_PORT'] == 80 || (isset ($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') || $_SERVER['SERVER_PORT'] == $https_port) ? '' : ':' . $_SERVER['SERVER_PORT'];
$site_url .= $base_url;
}
So if something is bad, it’s coming from the config.inc.php file.
I have, however, run across sites where the server does not report the expected values, especially if the site is using PHP as CGI with some kind of suexec. If the server is not configured correctly, the the SERVER array will contain values relating to the location of the PHP engine itself, rather than relating to your domain on the server. So you might get data for the actual physical server, not for your domain.