LAMP之Apache调优

一、环境的搭建

实验环境:

  操作系统:Centos 7.4

[root@xuegod70 ~]# ls
apr-1.6.3.tar.gz  apr-util-1.6.1.tar.bz2  httpd-2.4.33.tar.gz  pcre-8.41.tar.gz  #主要的按照包,下面是具体的安装操作
[root@xuegod70 ~]# yum install -y bzip2
[root@xuegod70 ~]# tar xf apr-1.6.3.tar.gz 
[root@xuegod70 ~]# ls
apr-1.6.3  apr-1.6.3.tar.gz  apr-util-1.6.1.tar.bz2  httpd-2.4.33.tar.gz  pcre-8.41.tar.gz
[root@xuegod70 ~]# cd apr-1.6.3
[root@xuegod70 apr-1.6.3]# yum install -y gcc gcc-c++     #安装依赖包
[root@xuegod70 apr-1.6.3]# ./configure --prefix=/usr/local/apr
[root@xuegod70 apr-1.6.3]# make && make install

[root@xuegod70 ~]# tar xf apr-util-1.6.1.tar.bz2 
[root@xuegod70 ~]# cd apr-util-1.6.1
[root@xuegod70 apr-util-1.6.1]# ./configure 
[root@xuegod70 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config 
[root@xuegod70 apr-util-1.6.1]# yum install expat-devel -y  #安装依赖包
[root@xuegod70 apr-util-1.6.1]# make && make install

[root@xuegod70 ~]# tar xf pcre-8.41.tar.gz 
[root@xuegod70 ~]# cd pcre-8.41
[root@xuegod70 pcre-8.41]# ./configure --prefix=/usr/local/pcre
[root@xuegod70 pcre-8.41]# make && make install  

二、隐藏Apache版本信息

1. 屏蔽apache版本等敏感信息

#查看apache版本信息:
[root@xuegod63 ~]# curl -I 192.168.1.63
HTTP/1.1 200 OK
Date: Sun, 15 Nov 2015 12:40:59 GMT
Server: Apache/2.4.33 (Unix) mod_ssl/2.4.33 OpenSSL/1.0.0-fips PHP/5.4.14
X-Powered-By: PHP/5.4.14
Content-Type: text/html

[root@xuegod63 ~]# curl -I www.baidu.com 
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Connection: Keep-Alive
Content-Length: 277
Content-Type: text/html
Date: Mon, 16 Jul 2018 08:32:29 GMT
Etag: "575e1f71-115"
Last-Modified: Mon, 13 Jun 2016 02:50:25 GMT
Pragma: no-cache
Server: bfe/1.0.8.18

[root@xuegod63 ~]# curl -I www.tencent.com
HTTP/1.1 200 OK
Server: NWS_UGC_HY
Connection: keep-alive
Date: Mon, 16 Jul 2018 08:32:58 GMT
Cache-Control: max-age=600
Expires: Mon, 16 Jul 2018 08:42:58 GMT
Last-Modified: Fri, 17 Feb 2017 02:11:37 GMT
Content-Type: text/html
Content-Length: 189
X-NWS-LOG-UUID: 0f1c8273-b0fa-4d9c-87ae-f6d9c5c8ca99 989f50f8bc1bbda11f966c017556085f
X-Cache-Lookup: Hit From Disktank


[root@xuegod63 ~]# curl -I www.taobao.com
HTTP/1.1 302 Found
Server: Tengine
Date: Mon, 16 Jul 2018 08:33:17 GMT
Content-Type: text/html
Content-Length: 258
Connection: keep-alive
Location: https://www.taobao.com/
Set-Cookie: thw=cn; Path=/; Domain=.taobao.com; Expires=Tue, 16-Jul-19 08:33:17 GMT;
Strict-Transport-Security: max-age=31536000

1、我们在apache主配置文件httpd.conf中,找到包含httpd-default.conf的行,并解开注释
[root@xuegod63 ~]# vim /usr/local/httpd/conf/httpd.conf
486 #Include conf/extra/httpd-default.conf
为:
486   Include conf/extra/httpd-default.conf
注意:编译安装的情况下,只有此行解开注释了,后面的修改才能生效。

2)打开httpd-default.conf文件,修改如下两个地方
[root@xuegod63 ~]# vim /usr/local/httpd/conf/extra/httpd-default.conf #修改如下行
改:
    55 ServerTokens Full
    65 ServerSignature On
为:
    ServerTokens Prod
    ServerSignature Off
注:  服务器标记产品
        服务器签名

重启服务:
[root@xuegod63 ~]# /etc/init.d/apachectl restart
测试:
[root@xuegod63 ~]# curl -I 192.168.1.63
HTTP/1.1 200 OK
Date: Sat, 29 Aug 2015 09:07:00 GMT
Server: Apache
X-Powered-By: PHP/5.4.14
Content-Type: text/html
注:还是会出现信息:Server: Apache

  

  

猜你喜欢

转载自www.cnblogs.com/happy1983/p/9318479.html
今日推荐