Manual:$wgServer

The base URL of the server, including protocol and without the trailing slash (eg, ). Since 1.18 MediaWiki has also supported setting $wgServer to a protocol-relative url (eg, ). This is used for supporting both HTTP and HTTPS with the same caches by using links that work under both protocols. When doing this can be used to set the full url including protocol that will be used in locations such as emails that don't support protocol relative urls.

This is used when producing fully-qualified URLs pointing to the wiki, for instance:
 * HTTP redirects on edit and to canonical URL spellings
 * print footer
 * links to articles from RSS/Atom feeds
 * and more!

Autodetection
When $wgServer is not set the default value is calculated automatically. Some web servers end up returning silly defaults or internal names which aren't what you want; for instance the ServerName directive in Apache's httpd.conf may not be set or detected properly by the system, leaving you with an unexpected. It's always good to configure the web server properly. But you are also always strongly recommended to set $wgServer explicitly in your LocalSettings.php as there are other bugs that may arise from allowing it to be auto-detected, such as cache pollution.

1.18
The installer sets this variable in. However, if it is not set in LocalSettings.php, the server name will be detected at run time using the method.