Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx variable for physical server name

Tags:

nginx

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 :(

like image 956
robert.bo.roth Avatar asked Jul 23 '14 15:07

robert.bo.roth


People also ask

What should be the server name in nginx?

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.

What does server_name _ mean in nginx?

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; }

What is host variable in nginx?

$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.


1 Answers

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.

like image 170
Luke Peterson Avatar answered Sep 25 '22 10:09

Luke Peterson