大家或许会有这种奇葩的需求...
要是同一台主机上, 需要针对不同的域名输出不同的Server头, 怎么实现呢?
我们需要用到ngx_headers_more模块
location / { if ( $host = 'segmentfault.com' ){ more_set_headers 'Server: Nginx'; } if ( $host = '0x01.segmentfault.com' ){ more_set_headers 'Server: Nginx_improved'; } .... }
我们追求极客的代码:
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'; } }