nginx server_name based on $hostname
Most variables in nginx only exist at runtime, not during configuration time.
For this reason, most variables cannot be used with the server_name
directive. Since $hostname
is a constant value, there's an explicit check for exactly $hostname
in the server_name
handler.
It only allows for the server_name
to be set to $hostname
, not static.$hostname
. You may be able to patch the source to make it support that feature (ngx_http_core_module.c
, look for $hostname
), but you can't do it with the existing code.