nginx隐藏版本号、错误信息页面隐藏nginx软件、修改 HTTP 头信息中的connection 字段,防止回显具体版本号、curl命令

目录

安装之后隐藏

 配置文件

源代码配置安装之前隐藏

修改nginx.h文件中的 13、14行

修改 HTTP 头信息中的connection 字段,防止回显具体版本号

配置文件49行

错误页面程序返回版本号、nginx隐藏

 配置文件36行

​编辑

安装nginx

相关选项说明

curl命令测试是否隐藏版本和软件

curl命令

#获取网页内容

将输出保存到文件中

发送POST请求

发送带有头部的请求

使用HTTP基本认证

从HTTPS网站不验证证书

上传文件

下载文件

显示响应头信息

 使用cookie

追踪重定向

使用代理服务器


安装之后隐藏

nginx隐藏版本号主要是出于安全考虑,某些nginx漏洞只存在特定的版本,如果攻击者知道了服务器使用的确切Nginx版本,他们可能会尝试利用这些已知漏洞进行攻击。因此,隐藏版本号可以提高服务器的安全性,使攻击者难以通过版本信息推断出服务器可能存在的安全漏洞。 

如果是已经安装则只能在nginx.conf配置文件中(http)添加隐藏版本号通常可以通过简单地修改Nginx的配置文件来实现。在Nginx的配置文件,http中添加server_tokens off;如果原本就有只需要将on改为off即可。指令可以关闭服务器发送包含版本信息的响应头,从而隐藏版本号。在http中是隐藏所有的server版本。

也可以在某个server中添加只隐藏server的。

vim /usr/local/nginx/conf/nginx.conf
vim /etc/nginx/conf/nginx.conf

 配置文件

http {
    server_tokens off;  # 在http块中关闭所有server的tokens

    server {
        listen 80;
        server_name example.com;

        # 可以在这里再次关闭,只针对这个server
        # server_tokens off;

        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
        }
    }
}

源代码配置安装之前隐藏

解压之后进入到nginx包下找到的src目录core目录中的nginx.h文件

vim /usr/src/nginx*/src/core/nginx.h

修改nginx.h文件中的 13、14行

(nginx1.26.1版本)不同版本可能会有不同。

不要去掉#号。

#define NGINX_VERSION      "1.26.1"
#此行代表版本号1.26.1
#define NGINX_VER          "nginx/" NGINX_VERSION    
#此行代表使用使用的软件是nginx

修改 HTTP 头信息中的connection 字段,防止回显具体版本号

拓展:通用 http 头 ,通用头包含请求和响应消息都支持的头,通用头包含 Cache-Control、 Connection 、Date 、Pragma 、Transfer-Encoding 、Upgrade 、Via。对通用头的扩展要求通讯双 方都支持此扩展,如果存在不支持的通用头,一般将会作为实体头处理。那么也就是说有部分设备、或者是软件,能获取到 connection,部分不能,为了安全要做到所有的有可能的漏洞彻底隐藏。

修改nginx目录中的src目录http目录ngx_header_fileter_module.c文件

vim src/http/ngx_http_header_filter_module.c

配置文件49行

(nginx1.26.1版本)不同版本可能会有不同。

static u_char ngx_http_server_string[] = "Server: nginx" CRLF;
#定义http错误码的返回。
例如:static u_char ngx_http_server_string[] = "Server: jingyu" CRLF;

错误页面程序返回版本号、nginx隐藏

修改nginx目录中的src目录http目录ngx_http_special_response.c 文件

vim src/http/ngx_http_special_response.c

 配置文件36行

(nginx1.26.1版本)不同版本可能会有不同。

static u_char ngx_http_error_tail[] =
"<hr><center>nginx</center>" CRLF
"</body>" CRLF
"</html>" CRLF
;
#修改前
static u_char ngx_http_error_tail[] =
"<hr><center>csdn-jingyu</center>" CRLF
"</body>" CRLF
"</html>" CRLF
;
#修改后

安装nginx

Nginx网站service 详细相关介绍-特点-http状态码-配置文件、将nginx添加永久环境变量 访问网站404是什么?_nginx 稳定版-CSDN博客

groupadd nginx
#添加 nginx 组
useradd -M -s /sbin/nologin -g nginx nginx
#创建 nginx 运行账户 nginx 并加入到 nginx 组,不允许 nginx 用户直接登录系统、没有家目录。
./configure --prefix=/usr/local/nginx1.26 \
--with-http_dav_module \
--with-http_stub_status_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_flv_module \
--with-http_mp4_module \
--user=nginx --group=nginx \
&& make && make install \

相关选项说明

--with-http_dav_module

#增加 PUT,DELETE,MKCOL:创建集合,COPY 和 MOVE 方法 

--with-http_stub_status_module

 #获取 Nginx 的状态统计信息

--with-http_addition_module

  #作为一个输出过滤器,支持不完全缓冲,分部分相应请求

--with-http_sub_module

  #允许一些其他文本替换 Nginx 相应中的一些文本

--with-http_flv_module

  #提供支持 flv 视频文件支持

--with-http_mp4_module

  #提供支持 mp4 视频文件支持,提供伪流媒体服务端支持

--with-http_ssl_module

#启用 ngx_http_ssl_module

curl命令测试是否隐藏版本和软件

curl -i 地址或域名

curl命令

curl 是一个在命令行或脚本中向/从服务器传输数据的工具,支持许多协议,如 HTTP、HTTPS、FTP 等。它是常用的Web服务器测试工具,也可以用于自动化的API测试。

#获取网页内容

curl http://example.com

将输出保存到文件中

curl -o filename.html http://example.com

发送POST请求

curl -d "param1=value1&param2=value2" -X POST http://example.com/resource

发送带有头部的请求

curl -H "Content-Type: application/json" -X POST -d '{"key1":"value1", "key2":"value2"}' http://example.com/resource

使用HTTP基本认证

curl -u username:password http://example.com

从HTTPS网站不验证证书

curl -k https://example.com

上传文件

curl -F "file=@path/to/local/file" http://example.com/upload

下载文件

curl -O http://example.com/file.tar.gz

显示响应头信息

curl -I http://example.com

 使用cookie

curl -b cookies.txt -c cookies_new.txt http://example.com

追踪重定向

curl -L http://example.com

使用代理服务器

curl -x proxy:port http://example.com
  • 18
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jingyu飞鸟

醒来觉得甚是爱你。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值