In Visualforce controllers, use ApexPages.currentPage().getHeaders().get(‘Host’) to get the server name (e.g., na1.salesforce.com).