nginx返回的服务器头怎么改? [英] How do you change the server header returned by nginx?

查看:17
本文介绍了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天全站免登陆