I'm trying to setup response headers on my separate webservers that outputs the physical name of the machine that nginx is running on, so that I can tell which servers are serving the responses to our web clients.
Is there a variable that exists to do this already? Or do I just have to hardcode it per-server :(
If it is required to process requests without the “Host” header field in a server block which is not the default, an empty name should be specified: server { listen 80; server_name example.org www.example.org ""; ... } If no server_name is defined in a server block then nginx uses the empty name as the server name.
As a convention, the underscore is used as a server name for default servers. From http://nginx.org/en/docs/http/server_names.html. In catch-all server examples the strange name “_” can be seen: server { listen 80 default_server; server_name _; return 444; }
$host is a variable of the Core module. $host. This variable is equal to line Host in the header of request or name of the server processing the request if the Host header is not available.
You're after the $hostname common variable. Common variables are listed in the variable index.
The nginx access log documentation only shows variables that are specific to the access log:
The log format can contain common variables, and variables that exist only at the time of a log write.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With