如何更改 nginx 返回的服务器标头? [英] How do you change the server header returned by nginx?

查看:62
本文介绍了如何更改 nginx 返回的服务器标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个选项可以隐藏版本,所以它只会显示 nginx,但是有没有办法也隐藏它,所以它不会显示任何内容或更改标题?

There's an option to hide the version so it will display only nginx, but is there a way to hide that too so it will not show anything or change the header?

推荐答案

和 Apache 一样,这是对源代码的快速编辑和重新编译.来自 Calomel.org:

Like Apache, this is a quick edit to the source and recompile. From Calomel.org:

服务器:字符串是标头被发回给客户告诉他们是什么类型的 http 服务器运行,可能是什么版本.这个字符串被像这样的地方使用Alexia 和 Netcraft 收集关于多少和什么的统计网络服务器的类型在互联网.为了支持作者和我们推荐的 Nginx 统计信息保持这个字符串不变.但对于您可能不希望人们使用的安全性知道你在跑什么,你可以在源代码中更改它.编辑源文件src/http/ngx_http_header_filter_module.c看看第 48 和 49 行.你可以将字符串更改为您的任何内容想要.

The Server: string is the header which is sent back to the client to tell them what type of http server you are running and possibly what version. This string is used by places like Alexia and Netcraft to collect statistics about how many and of what type of web server are live on the Internet. To support the author and statistics for Nginx we recommend keeping this string as is. But, for security you may not want people to know what you are running and you can change this in the source code. Edit the source file src/http/ngx_http_header_filter_module.c at look at lines 48 and 49. You can change the String to anything you want.

## vi src/http/ngx_http_header_filter_module.c (lines 48 and 49)
static char ngx_http_server_string[] = "Server: MyDomain.com" CRLF;
static char ngx_http_server_full_string[] = "Server: MyDomain.com" CRLF;

2011 年 3 月 支持 Flavius 指出一个新选项,替换 Nginx 的标准 HttpHeadersModule 与分叉的 HttpHeadersMoreModule.重新编译标准模块仍然是快速修复,如果您想使用标准模块并且不会经常更改服务器字符串,那么它是有意义的.但是,如果您想要更多,HttpHeadersMoreModule 是一个强大的项目,它可以让您使用 HTTP 标头执行各种运行时黑魔法.

March 2011 edit: Props to Flavius below for pointing out a new option, replacing Nginx's standard HttpHeadersModule with the forked HttpHeadersMoreModule. Recompiling the standard module is still the quick fix, and makes sense if you want to use the standard module and won't be changing the server string often. But if you want more than that, the HttpHeadersMoreModule is a strong project and lets you do all sorts of runtime black magic with your HTTP headers.

这篇关于如何更改 nginx 返回的服务器标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆