自定义nginx版本号

直接将nginx的版本号修改成主机标识(比如IP末位),这样既隐藏了版本号,又增加了排障效率。


具体办法是修改nginx的源码 src/core/nginx.h,源文件如下

/*
 * 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命令即可,示例如下

%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 中注释掉

# server_tokens off;


效果图

163356126.jpg



使用chrome插件HTTP Headers可以非常方便的查看页面头部信息。

163359250.jpg

163401437.jpg


是不是挺有意思的呢?


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值