zoukankan      html  css  js  c++  java
  • centos6.5-Apache优化

    Apache的网页压缩功能

    一、配置网页压缩功能

    在配置压缩功能以前访问网页的响应头部

     

    Response Headers

    view source

    Accept-Ranges:bytes

    Connection:Keep-Alive

    Content-Length:40

    Content-Type:text/html

     

     

     (1)安装apache,开启网页压缩功能

    ./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi --enable-deflate

    make && make install

    (2)修改配置文件,启用压缩功能

    在配置文件的最后加入以下三行

    vim /usr/local/httpd/conf/httpd.conf

    AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml text/javascript

    DeflateCompressionLevel 9

    SetOutputFilter DEFLATE

    配置完成后在次访问,查看响应头部

    1. Accept-Ranges:bytes
    2. Connection:Keep-Alive
    3. Content-Encoding:gzip
    4. Content-Length:57

     

    第一行:表示对什么样的内容启用gzip压缩

    第二行:代表压缩级别

    第三行:启用deflate模块对本站点的输出进行gizp压缩

     

    /usr/local/httpd/bin/apachectl restart  #重启服务

    二、开启网页缓存功能

    1.查看是否开启了expires模块

    [root@localhost htdocs]# /usr/local/httpd/bin/apachectl -t -D DUMP_MODULES |grep expires

    Syntax OK

    2.重新编译安装

    ./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite--enable-charset-lite --enable-cgi --enable-deflate --enable-expires

    3.修改配置文件,启用缓存功能

    在文件最后加入以下内容

    <IfModule mod_expires.c>

            ExpiresActive On

            ExpiresDefault "access plus 60 seconds"

    </IfModule>

    三、 apache的防盗链

    1.修改windowshosts文件

        C:WindowsSystem32driversetc

        修改hosts文件 增加以下内容

        192.168.3.10 www.benet.com

        192.168.3.10 www.accp.com

    2.编译安装apache,配置基于域名的虚拟主机

    (1)创建虚拟用户的网页根目录

    cd /usr/local/httpd/htdocs/

    mkdir benetcom

    cd benetcom

    echo "<h1>benet</h1>" > index.html

    cd ../

    mkdir accpcom

    cd accpcom

    echo "<h1>accp</h1>" > index.html

    (2)修改虚拟用户的配置文件

    cd /usr/local/httpd/conf/extra/

    vim httpd-vhosts.conf  #更改配置文件,修改红色部分内容

    NameVirtualHost 192.168.25.105  #更改19  更改为web服务器(本机)的IP地址

    <VirtualHost 192.168.25.105> 

     DocumentRoot /usr/local/httpd/htdocs/benetcom/

     ServerName www.benet.com

     ErrorLog "logs/benet-error_log"

     CustomLog "logs/benet-access_log" common

    </VirtualHost>

    <VirtualHost 192.168.25.105>

     DocumentRoot /usr/local/httpd/htdocs/accpcom/

     ServerName www.accp.com

     ErrorLog "logs/accp-error_log"

     CustomLog "logs/accp-access_log" common

    </VirtualHost>

    3)修改主配置文件

    vim /usr/local/httpd/conf/httpd.conf

    #在最后一行添加以下内容,加载外部的虚拟用户的配置文件

    Include conf/extra/httpd-vhosts.conf

    重启服务

    (4)修改benet.com的默认首页

    vim index.html  #添加以下内容,将图片传到benetcom目录下,并改名为a.jpg

    <h1>benet</h1>

    <img src="a.jpg" />

     

    (5)修改盗链主机 accp虚拟主机

    cd accpcom/

    vim index.html

    <img src="http://www.benet.com/a.jpg" />

     

    (6)修改主配置文件

    vim /usr/local/httpd/conf/httpd.conf

    在157行下添加以下内容

    RewriteEngine On

        RewriteCond %{HTTP_REFERER} !^http://benet.com/.*$ [NC]

        RewriteCond %{HTTP_REFERER} !^http://benet.com/$ [NC]

        RewriteCond %{HTTP_REFERER} !^http://www.benet.com/.*$ [NC]

        RewriteCond %{HTTP_REFERER} !^http://www.benet.com/$ [NC]

        RewriteRule .*.(gif|jpg|swf)$ http://www.benet.com/error.html [R,NC]

    重启服务,再次访问accp.com发现无法加载图片

    echo "error" > /usr/local/httpd/htdocs/benetcom/error.html

    四、隐藏版本号

    vim /usr/local/httpd/conf/httpd.conf

    Include conf/extra/httpd-default.conf  #在后一行加入此行内容

     

    vim /usr/local/httpd/conf/extra/httpd-default.conf

    #修改以下两行

    ServerTokens prod

    ServerSignature Off

  • 相关阅读:
    spring框架基本操作
    HTML 小练习(静态网页)
    sqldeveloper 连接oracle失败报12514(日常错误)
    基于docker容器搭建fastdfs分布式文件系统
    centos7 64位系统jdbc连接oracle报错问题
    openstack kolla多节点容器化环境安装
    Android TabHost设置setCurrentTab(index),当index!=0时,默认加载第一个tab问题解决方法。
    maven导入dom4j以及jaxen.jar报java.lang.UnsupportedOperationException:错误
    android自学笔记(1):android简介
    Linux命令(7):rm命令
  • 原文地址:https://www.cnblogs.com/pangbing/p/6534506.html
Copyright © 2011-2022 走看看