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

查看:768
本文介绍了你如何更改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道具,用分叉的 HttpHeadersModule HttpHeadersMoreModulerel =noreferrer> 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天全站免登陆