Nginx implementation of different domain name output different Server header information method _nginx

Source: Internet
Author: User

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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.