直接将nginx的版本号修改成主机标识(比如IP末位),这样既隐藏了版本号,又增加了排障效率。
具体办法是修改nginx的源码 src/core/nginx.h,源文件如下
1
2
3
4
5
6
7
8
9
10
11
12
|
/*
* Copyright (C) Igor Sysoev
* Copyright (C) Nginx, Inc.
*/
#ifndef _NGINX_H_INCLUDED_
#define _NGINX_H_INCLUDED_
#define nginx_version
1004002
#define NGINX_VERSION
"1.4.2"
#define NGINX_VER
"nginx/"
NGINX_VERSION
#define NGINX_VAR
"NGINX"
#define NGX_OLDPID_EXT
".oldbin"
#endif
/* _NGINX_H_INCLUDED_ */
|
修改版本号只需要修改1.4.2 即可,当然,修改nginx名称为别的也行。
具体到rpm打包,只需要增加一行sed命令即可,示例如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
%build
sed -i
'/NGINX_VERSION/{s/1.4.2/114/g}'
src/core/nginx.h
./configure \
--prefix=%{_sysconfdir}/nginx \
--sbin-path=%{_sbindir}/nginx \
--conf-path=%{_sysconfdir}/nginx/nginx.conf \
--error-log-path=%{_localstatedir}/log/nginx/error.log \
--http-log-path=%{_localstatedir}/log/nginx/access.log \
--pid-path=%{_localstatedir}/run/nginx.pid \
--lock-path=%{_localstatedir}/run/nginx.lock \
--http-client-body-temp-path=%{_localstatedir}/cache/nginx/client_temp \
--http-proxy-temp-path=%{_localstatedir}/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=%{_localstatedir}/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=%{_localstatedir}/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=%{_localstatedir}/cache/nginx/scgi_temp \
--user=%{nginx_user} \
--group=%{nginx_group} \
--
with
-http_ssl_module \
--
with
-http_realip_module \
--
with
-http_gzip_static_module \
--
with
-http_stub_status_module \
--
with
-google_perftools_module \
--add-module=%{_builddir}/nginx-%{version}/nginx_upstream_hash \
--add-module=%{_builddir}/nginx-%{version}/naxsi-core-
0.50
/naxsi_src \
--add-module=%{_builddir}/nginx-%{version}/ngx_cache_purge \
--add-module=%{_builddir}/nginx-%{version}/ngx_pagespeed-release-
1.6
.
29.5
-beta \
--add-module=%{_builddir}/nginx-%{version}/nginx-sticky-module-
1.1
\
--
with
-file-aio \
--
with
-debug \
--
with
-cc-opt=
"%{optflags} $(pcre-config --cflags)"
\
$*
make %{?_smp_mflags}
|
记得在nginx.conf 中注释掉
1
|
# server_tokens off;
|
效果图
使用chrome插件HTTP Headers可以非常方便的查看页面头部信息。
是不是挺有意思的呢?
本文转自 紫色葡萄 51CTO博客,原文链接:http://blog.51cto.com/purplegrape/1291871,如需转载请自行联系原作者