nginx中间件信息隐藏
nginx中间件信息隐藏
此处为nginx加固,对nginx的中间件信息和版本号进行隐藏。
此处使用debian系统,不同发行版对于nginx所需要的依赖安装包名不相同,原理相同(https://www.cnblogs.com/Dpkg/p/13218830.html)。
一:安装好不想重编译只想隐藏版本号
二:重编译重新安装
三:不重编译的也能达到重新编译的安全效果
一、对于隐藏版本号其实比较简单直接在安装好的nginx目录下的修改nginx.conf文件在http模块下面增加(这种配置有弊端不能在根本上修改中间件信息,很多php探针还是能够识别出来这个版本号信息,二是针对的教程):
server_tokens off;
二、要想在根本上解决这个问题必须对nginx中间件源码进行重编译,修改nginx的源码,这时的中间件信息和版本号可以自定义。
1.下载nginx安装包http://nginx.org/en/download.html,根据自己想的版本进行下载(提前安装依赖https://www.cnblogs.com/Dpkg/p/13218830.html)
tar -xzvf nginx-1.18.0
2.进入解压后的文件夹下面,对三个文件进行内容修改:
1./src/core/nginx.h
#define NGINX_VERSION "1.8.0" #版本信息 #define NGINX_VER "NGINX/" NGINX_VERSION #中间件名称
2./src/http/ngx_http_header_filter_module.c
static char ngx_http_server_string[] = "Server: nginx" CRLF; #响应头中间件信息
3./src/http/ngx_http_special_response.c
static u_char ngx_http_error_tail[] = "<hr><center>nginx</center>" CRLF "</body>" CRLF "</html>" CRLF ; #此为一些报错页面下面显示的中间件名称
2.进行编译安装
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-pcre && make && make install #--prefix=是你准备要安装的路径,此路径编译后进行安装后里面的nginx执行文件就不能改变位置
#--with-http_ssl_module --with-pcre是安装后支持https
3.常规操作
[root@localhost ~]# /usr/local/nginx/sbin/nginx 启动 [root@localhost ~]# /usr/local/nginx/sbin/nginx -s stop 停止 [root@localhost ~]# /usr/local/nginx/sbin/nginx -s reload 重新载入 [root@localhost ~]# /usr/local/nginx/sbin/nginx -v 查看版本 [root@localhost ~]# /usr/local/nginx/sbin/nginx -t 测试配置文件是否正常
三、不想重新安装又想达到编译的效果,这种方式利用平滑升降级的方法对其进行重编译(你原先安装的nginx是用源码安装的)。
1.其实在你原先的安装步骤上去掉最后一步make install,但是在编译的路径--prefix=要设置在旧的文件夹下,进行编译后会在nginx-1.18.0的文件夹下生成objs问价夹,之后将objs文件夹下面的新的nginx覆盖掉原先的旧的nginx执行文件。
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-pcre && make
#此处一定去掉最后的make install