调整参数隐藏Nginx软件版本信息号

参考资料

[1]. 跟老男孩学Linux运维:Web集群实战,老男孩

安装过程

查看本机信息

[root@www ~]# curl -I 127.0.0.1

server_tokens

在Nginx配置文件nginx.conf 中的http标签段内加入 server_tokens off; 参数

http 
{
    server_tokens off;
}

此参数放置在http标签内,作用是控制http response header 内的Web 服务版本信息的显示,以及错误信息中Web服务版本信息的显示。

server_tokens 参数的官方说明

syntax: server_tokens on | off; # 此行为参数语法,on为开启状态,off为关闭状态
default: server_tokens on; # 默认为开启
context: http, server, location # server_tokens 参数可以放置的位置

重启并测试

[root@www conf]# /application/nginx/sbin/nginx -t
[root@www conf]# /application/nginx/sbin/nginx -s reload
[root@www conf]# curl -I 127.0.0.1

更改源码隐藏Nginx软件名及版本号

寻找 nginx.h 文件路径

[root@www ~]# find / -name nginx.h

## 编辑第一个文件
[root@www ~]# vim /home/oldboy/tools/nginx-1.9.9/src/core/nginx.h
## 编辑以下项目
#define NGINX_VERSION      "1.9.1"
#define NGINX_VER          "nginx/" NGINX_VERSION
#define NGINX_VAR          "NGINX"

## 修改后,内容如下
#define NGINX_VERSION      "0.1"
#define NGINX_VER          "www/" NGINX_VERSION
#define NGINX_VAR          "www"

## 编辑第二个文件

[root@www http]# grep -n 'Server: nginx' /home/oldboy/tools/nginx-1.9.9/src/http/ngx_http_header_filter_module.c
[root@www http]# sed -i 's#Server: nginx#Server: www#g' /home/oldboy/tools/nginx-1.9.9/src/http/ngx_http_header_filter_module.c
[root@www http]# grep -n 'Server: www' /home/oldboy/tools/nginx-1.9.9/src/http/ngx_http_header_filter_module.c

## 编辑第三个文件
[root@www http]# vim /home/oldboy/tools/nginx-1.9.9/src/http/ngx_http_special_response.c 
## 编辑以下文件
"<hr><center>" NGINX_VER "</center>" CRLF       ## 约21行
"<hr><center>nginx</center>" CRLF               ## 约28行

## 编辑后的内容
"<hr><center>" NGINX_VER " (www.shuaige.com)</center>" CRLF     ## 约21行
"<hr><center>www</center>" CRLF             ## 约28行
5. 重新编译并再次使用curl 命令查看


[root@www nginx-1.9.9]# service nginx stop
[root@www nginx-1.9.9]# cd /home/oldboy/tools/nginx-1.9.9
[root@www nginx-1.9.9]# ./configure --user=nginx --group=nginx --prefix=/application/nginx-1.9.9/ --with-http_stub_status_module --with-http_ssl_module
[root@www nginx-1.9.9]# make
[root@www nginx-1.9.9]# make install
[root@www nginx-1.9.9]# service nginx start
[root@www nginx-1.9.9]# curl -I 127.0.0.1

更改Nginx服务的默认用户

## 查看Nginx服务对应的默认用户
[root@www ~]# cd /application/nginx/conf
[root@www conf]# grep '#user' nginx.conf.default
## 为Nginx服务建立新用户
[root@www ~]# useradd nginx -s /sbin/nologin -M
[root@www ~]# id nginx  ## 检查用户


## 配置Nginx用户的方法1
[root@www ~]# vim /application/nginx/conf
## 将默认的 #user nobody 修改为 user nginx nginx

## 配置Nginx用户的方法2
在编译的时候加上 --user=nginx 和 --group=nginx 两个参数
./configure --user=nginx --group=nginx --prefix=/application/nginx-1.9.9/ --with-http_stub_status_module --with-http_ssl_module

## 检查Nginx的用户情况
[root@www conf]# ps -ef|grep nginx|grep -v grep
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值