Do not use HTTP_HOST because this can be incorrect behind a reverse proxy.