gwuj 发表于 2018-11-21 13:23:33

隐藏Apache Nginx PHP版本显示

  ###############################################################################
  隐藏Apache版本号
  ###############################################################################
  # curl -I 192.168.93.143
  HTTP/1.1 403 Forbidden
  Date: Wed, 21 Jul 2010 13:09:33 GMT
  Server: Apache/2.2.15 (CentOS)
  Accept-Ranges: bytes
  Content-Length: 5043
  Connection: close
  Content-Type: text/html;
  隐藏方法:
  1、隐藏Apache版本号的方法是修改Apache的配置文件,如RedHat系的Linux默认是:
  vim /etc/httpd/conf/httpd.conf
  分别搜索关键字ServerTokens和ServerSignature,修改:
  ServerTokens OS 修改为 ServerTokens ProductOnly
  ServerSignature On 修改为 ServerSignature Off
  2、重启或重新加载Apache就可以了。
  apachectl restart
  测试一下,如下:
  # curl -I 192.168.93.143
  HTTP/1.1 403 Forbidden
  Date: Wed, 21 Jul 2010 13:23:22 GMT
  Server: Apache
  Accept-Ranges: bytes
  Content-Length: 5043
  Connection: close
  Content-Type: text/html; charset=UTF-8
  版本号与操作系统信息已经隐藏了。
  3、上面的方法是默认情况下安装的Apache,如果是编译安装的,还可以用修改源码编译的方法:
  进入Apache的源码目录下的include目录,然后编辑ap_release.h这个文件,你会看到有如下变量:
  #define AP_SERVER_BASEVENDOR “Apache Software Foundation”
  #define AP_SERVER_BASEPROJECT “Apache HTTP Server”
  #define AP_SERVER_BASEPRODUCT “Apache”
  #define AP_SERVER_MAJORVERSION_NUMBER 2
  #define AP_SERVER_MINORVERSION_NUMBER 2
  #define AP_SERVER_PATCHLEVEL_NUMBER 15
  #define AP_SERVER_DEVBUILD_BOOLEAN 0
  可以根据自己喜好,修改或隐藏版本号与名字。
  ###############################################################################
  隐藏Nginx PHP版本号
  ###############################################################################
  Nginx默认是显示版本号的:
  # curl -I www.nginx.org
  HTTP/1.1 200 OK
  Server: nginx/0.8.44
  Date: Tue, 13 Jul 2010 14:05:11 GMT
  Content-Type: text/html
  Content-Length: 8284
  Last-Modified: Tue, 13 Jul 2010 12:00:13 GMT
  Connection: keep-alive
  Keep-Alive: timeout=15
  Accept-Ranges: bytes
  nginx隐藏版本号的步骤:
  1、进入nginx配置文件的目录(此目录根据安装时决定),用vim编辑打开
  vim nginx.conf
  在http {—}里加上server_tokens off; 如:
  http {
  ……省略
  sendfile on;
  tcp_nopush on;
  keepalive_timeout 60;
  tcp_nodelay on;
  server_tokens off;
  …….省略
  }
  2、编辑php-fpm配置文件,如fastcgi.conf或fcgi.conf(这个配置文件名也可以自定义的,根据具体文件名修改):
  找到:
  fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
  改为:
  fastcgi_param SERVER_SOFTWARE nginx;
  3、重新加载nginx配置:

  # /etc/init.d/nginx>  这样就完全对外隐藏了nginx版本号了,就是出现404、501等页面也不会显示nginx版本。
  下面测试一下:
  # curl -I www.abc.net
  HTTP/1.1 200 OK
  Server: nginx
  Date: Tue, 13 Jul 2010 14:26:56 GMT
  Content-Type: text/html; charset=UTF-8
  Connection: keep-alive
  Vary: Accept-Encoding
  源代码安装时修改方法:
  vi /src/core/nginx.h
  修改其中:
  #define NGINX_VERSION “1.0″
  #define NGINX_VER “GWS/” NGINX_VERSION
  重新编译nginx;
  以上就是伪装Nginx,隐藏Nginx版本号全部过程。
  二、隐藏PHP版本号
  首先进入php.ini文件的目录(这里不区分源码安装还是yum或者apt-get):
  vi php.ini
  找到:
  expose_php = On;
  修改为:
  expose_php = Off;
  重启!
  以上就是隐藏Apache,Nginx、PHP版本号并提升服务器安全性全部过程。

页: [1]
查看完整版本: 隐藏Apache Nginx PHP版本显示