I keep reading that in nginx config files, we should hardcode hostnames instead of using variables.
For example:
server_name www.example.com example.com;
return 301 https://www.example.com$request_uri;
instead of
server_name www.example.com example.com;
return 301 https://$host$request_uri;
I find it surprising that nginx wouldn't cache static config upon start.
Is there official documentation about this somewhere, or is it just anecdotal?
$host
is not a static variable but based on the headers in the original request. If you only host one website, then hardcoding the website name is not an issue, but if you host many websites, you may require a flexible configuration that does not contain the nameexample.com
. – Richard Smith Oct 11 at 10:34www.www.example.com
. – Richard Smith Oct 11 at 11:26