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

  • 相关阅读:
    【BZOJ2844】albus就是要第一个出场 高斯消元求线性基
    Python入门之面向对象module,library,package之间区别
    Python入门之字典的操作详解
    Python Web学习笔记之TCP/IP协议原理与介绍
    Python Web笔记之高性能网络编程
    Python Web学习笔记之面试TCP的15个问题
    Python Web学习笔记之TCP/IP、Http、Socket的区别
    Python Web学习笔记之TCP、UDP、ICMP、IGMP的解释和区别
    Python Web学习笔记之IGMP和ICMP的差别
    Python设计模式之单例模式
  • 原文地址:https://www.cnblogs.com/pangbing/p/6534506.html
Copyright © 2011-2022 走看看