• 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

     配置文件

    1. http {
    2. server_tokens off; # 在http块中关闭所有server的tokens
    3. server {
    4. listen 80;
    5. server_name example.com;
    6. # 可以在这里再次关闭,只针对这个server
    7. # server_tokens off;
    8. location / {
    9. root /usr/share/nginx/html;
    10. index index.html index.htm;
    11. }
    12. }
    13. }

    源代码配置安装之前隐藏

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

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

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

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

    不要去掉#号。

    1. #define NGINX_VERSION "1.26.1"
    2. #此行代表版本号1.26.1
    3. #define NGINX_VER "nginx/" NGINX_VERSION
    4. #此行代表使用使用的软件是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版本)不同版本可能会有不同。

    1. static u_char ngx_http_server_string[] = "Server: nginx" CRLF;
    2. #定义http错误码的返回。
    3. 例如: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版本)不同版本可能会有不同。

    1. static u_char ngx_http_error_tail[] =
    2. "
      nginx
      "
      CRLF
    3. "" CRLF
    4. "" CRLF
    5. ;
    6. #修改前
    1. static u_char ngx_http_error_tail[] =
    2. "
      csdn-jingyu
      "
      CRLF
    3. "" CRLF
    4. "" CRLF
    5. ;
    6. #修改后

    安装nginx

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

    1. groupadd nginx
    2. #添加 nginx 组
    3. useradd -M -s /sbin/nologin -g nginx nginx
    4. #创建 nginx 运行账户 nginx 并加入到 nginx 组,不允许 nginx 用户直接登录系统、没有家目录。
    1. ./configure --prefix=/usr/local/nginx1.26 \
    2. --with-http_dav_module \
    3. --with-http_stub_status_module \
    4. --with-http_addition_module \
    5. --with-http_sub_module \
    6. --with-http_flv_module \
    7. --with-http_mp4_module \
    8. --user=nginx --group=nginx \
    9. && 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¶m2=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
    
  • 相关阅读:
    【Unity】Inspector排版扩展学习初探
    【Mac】Mac与PlayCover、Mac关闭sip
    (微信开发)Laya转发H5网页到微信,带图片
    阿里云 Serverless 异步任务处理系统在数据分析领域的应用
    vue中echart-gl 3D地图纹理实例
    SpringBoot整合Zookeeper集群下实现分布式锁
    拓展卡尔曼滤波(Kalman)附Matlab代码
    基于YOLOv8/YOLOv7/YOLOv6/YOLOv5的条形码二维码检测系统(深度学习+UI界面+训练数据集+Python代码)
    Linux-Centos7安装Docker
    axios 源码简析
  • 原文地址:https://blog.csdn.net/2301_77161927/article/details/139348772