We may have this kind of wonderful demand ...
If the same host, the need for different domain name output different server headers, how to achieve it?
We need to use the Ngx_headers_more module.
Copy Code code as follows:
Location/{
if ($host = ' segmentfault.com ') {
More_set_headers ' Server:nginx ';
}
if ($host = ' 0x01.segmentfault.com ') {
More_set_headers ' server:nginx_improved ';
}
....
}
Like the above, we can implement this function.
But is that a reliable thing? Reliable, but not satisfied with A.r.g.u.s. Coding style, we never allow ugly code to make people look at jokes.
Our pursuit of Geek code:
Copy Code code as follows:
Map $host $server _x_tag{
' segmentfault.com ' ' Nginx ';
' 0x01.segmentfault.com ' ' nginx_improved ';
Default ' Nginx ';
}
server{
SERVER_NAME 123;
Location/{
More_set_headers ' Server: $server _x_tag ';
}
}
Is it better to look like this?