Nginx隐藏版本号
<代码>在生产环境中,需要隐藏Nginx的版本号,以避免安全漏洞的泄露代码>
查看方法
<代码>使用提琴手工具在Windows客户端查看Nginx版本号
在centos系统中使用“旋度我网址”命令查看代码>
Nginx隐藏版本号的方法
<代码>修改配置文件法
修改源码法代码>
一、安装Nginx
1,在Linux上使用远程共享获取文件并挂载到mnt目录下
<代码> [root@localhost ~] # smbclient - l//192.168.100.3/# #远程共享访问
进入SAMBA \ root的密码:
Sharename类型的评论
- - - - - - - - - - - - - - - - - - - - - - - -
LNMP-C7磁盘
root@localhost ~ #山。cifs//192.168.100.3/LNMP-C7/mnt # #挂载到/mnt目录下代码>
2,解压源码包到/opt下,并查看
<代码> [root@localhost ~] # cd/mnt # #切换到挂载点目录
[root@localhost mnt] # ls
Discuz_X3.4_SC_UTF8。zip nginx-1.12.2.tar.gz
mysql-boost-5.7.20.tar。广州php-7.1.20.tar.gz
[root@localhost mnt] #焦油zxvf nginx-1.12.2.tar。广州- c/opt # #解压Nginx源码包到/opt下
[root@localhost mnt] # cd/opt/# #切换到解压的目录下
root@localhost选择# ls
nginx-1.12.2 rh 代码>
3,安装编译需要的环境组件包
<代码>安装\ [root@localhost选择]# yum - y
gcc \//c语言
gcc-c + + \//c++语言
pcre-devel \//pcre语言工具
zlib-devel//数据压缩用的函式库代码>
4,创建程序用户nginx并编译nginx
<代码> [root@localhost选择]# useradd - m - s/sbin/nologin nginx # #创建程序用户,安全不可登陆状态
[root@localhost选择]# id nginx
uid=1001 (nginx) gid=1001 (nginx)组=1001 (nginx)
[root@localhost选择]# cd nginx-1.12.0/# #切换到nginx目录下
[root@localhost nginx-1.12.0] # ./configure \ # #配置nginx
比;——prefix=/usr/地方/nginx \ # #安装路径
比;——用户=nginx \ # #用户名
比;——组=nginx \ # #用户组
比;——with-http_stub_status_module # #状态统计模块代码>
5,编译和安装
<代码> [root@localhost nginx-1.12.0] #让# #编译
…
[root@localhost nginx-1.12.0] # make install # #安装
…
[root@localhost nginx] # ln - s/usr/local/nginx/sbin/nginx/usr/local/sbin/# #创建软连接让系统识别nginx启动脚本代码>
6,制作管理脚本,便于使用服务管理使用
<代码> [root@localhost nginx] # cd/etc/init.d/# #切换到启动配置文件目录
[root@localhost init。d] # ls
函数netconsole网络自述
[root@localhost init。d] # vim nginx # #编辑启动脚本文件
# !/bin/bash
20 # # # chkconfig: - 99注释信息
描述:Nginx服务控制脚本
学监="/usr/地方/nginx/sbin/nginx”# #设置变量为nginx命令文件
PIDF="/usr/地方/nginx/logs/nginx。pid”# #设置变量pid文件进程号为5346
“1美元”
开始)
美元掠夺# #开启服务
;;
停止)
杀- s退出美元(猫PIDF美元)# #关闭服务
;;
重启)# #重启服务
0美元停止
$ 0开始
;;
重载)# #重载服务
杀- s玫瑰(猫PIDF美元美元)
;;
*)# #错误输入提示
回声”用法:$ 0{启动|停止| |重启重载}”
出口1
esac
退出0
[root@localhost init。d] # chmod + x/etc/init.d/nginx # #给启动脚本执行权限
[root@localhost init。d] # chkconfig——添加nginx # #添加到服务管理器中
[root@localhost init。d] nginx停止# # #服务就可以使用服务控制nginx
[root@localhost init。d] #服务nginx开始代码>
二、隐藏版本号
<代码> [root@localhost init。d] # curl - http://192.168.13.140/# #查看Nginx信息
HTTP/1.1 200 OK
服务器:nginx/1.12.2 # #显示版本号
时间:星期二,2019年11月12日14:23:24格林尼治时间
内容类型:text/html
内容长度:612
最后修改:星期二,2019年11月12日13:46:35格林尼治时间
连接:维生
ETag:“5 dcab7bb - 264”
Accept-Ranges:字节
[root@localhost init。d] # vim/usr/local/nginx/conf/nginx.参看# #修改配置文件
http{# #在http下添加
包括mime.types;
default_type应用程序/八进制;
server_tokens;# #关闭版本号
[root@localhost init。d] #服务nginx停止# #关闭服务
[root@localhost init。d] #服务nginx开始# #开启服务
[root@localhost init。d] # curl - http://192.168.13.140/# #查看Nginx信息
HTTP/1.1 200 OK
服务器:nginx # #版本号被隐藏
时间:星期二,2019年11月12日14:22:00格林尼治时间
内容类型:text/html
内容长度:612
最后修改:星期二,2019年11月12日13:46:35格林尼治时间
连接:维生
ETag:“5 dcab7bb - 264”
Accept-Ranges:字节代码