zoukankan      html  css  js  c++  java
  • Apache常用配置项

    301是永久重定向

    302是临时重定向

    编辑虚拟主机的配置文件需要用到apache的rewrite模块

    所以要用要先检查apache是否安装了rewrite模块

    # ./bin/apachectl -M | grep rewrite

     rewrite_module (shared)

    # vim /usr/local/apache/conf/extra/httpd-vhosts.conf

    <IfModule mod_rewrite.c>

         RewriteEngine on

         RewriteCond %{HTTP_HOST} ^www.aaa.com$ [OR]

         RewriteCond %{HTTP_HOST} ^www.bbb.com$

         RewriteRule ^/(.*)$ http://www.fansik.com/$1 [R=301,L]

    </IfModule>

    Apache日志切割

    CustomLog "|/usr/local/apache/bin/rotatelogs -l /usr/local/apache/logs/discuz-access_%Y%m%d_log 86400" combined

    Apache不记录以下结尾的内容

        SetEnvIf Request_URI ".*.gif$" image-request

        SetEnvIf Request_URI ".*.jpg$" image-request

        SetEnvIf Request_URI ".*.png$" image-request

        SetEnvIf Request_URI ".*.bmp$" image-request

        SetEnvIf Request_URI ".*.swf$" image-request

        SetEnvIf Request_URI ".*.js$" image-request

        SetEnvIf Request_URI ".*.css$" image-request

    CustomLog "|/usr/local/apache/bin/rotatelogs -l /usr/local/apache/logs/discuz-access_%Y%m%d_log 86400" combined env=!image-request

    Apache配置静态缓存

    <IfModule mod_expires.c>
      ExpiresActive on
      ExpiresByType image/gif "access plus 1 days"
      ExpiresByType image/jpeg "access plus 24 hours"
      ExpiresByType image/png "access plus 24 hours"
      ExpiresByType text/css "now plus 2 hours"
      ExpiresByType application/x-javascript "now plus 2 hours"
      ExpiresByType application/x-shockwave-flash "now plus 2 hours"
      ExpiresDefault "now plus 0 min"
    </IfModule>

    加载好上面的配置后可用curl来检查一下哦

    # curl -x127.0.0.1:80 'http://120.55.194.217/static/image/common/logo.png' -I

    如果出现红字,说明配置成功了,缓存时间是86400秒

    HTTP/1.1 200 OK

    Date: Tue, 15 Mar 2016 06:10:29 GMT

    Server: Apache/2.4.6 (Unix) PHP/5.6.6

    Last-Modified: Tue, 08 Dec 2015 02:39:16 GMT

    ETag: "1149-52659e1375d00"

    Accept-Ranges: bytes

    Content-Length: 4425

    Cache-Control: max-age=86400

    Expires: Wed, 16 Mar 2016 06:10:29 GMT

    Content-Type: image/png

    如果没效果记得查看一下模块的开关是不是打开了

    Apache防盗链

    SetEnvIfNoCase Referer "^http://.*.discuz.com" local_ref
    SetEnvIfNoCase Referer ".*.luntan.com" local_ref
    < filesmatch ".(txt|doc|mp3|zip|rar|jpg|gif|png|js|css)">
        Order Allow,Deny
        Allow from env=local_ref
    < /filesmatch>

    Apache访问控制(只允许本机访问admin的管理页面admin)

    <filesmatch "(.*)admin(.*)">

            Order deny,allow

            Deny from all

            Allow from 127.0.0.1

    <filesmatch>

    Apache禁止解析某个目录下的php文件

    <Directory /opt/discuz>

            php_admin_flag engine off

            <filesmatch "(.*)php">

                    Order deny,allow

                    Deny from all

            </filesmatch>

    </Directory>

     Apache禁止指定user_agent

    <IfModule mod_rewrite.c>

            RewriteCond %{HTTP_USER_AGENT} ^.*curl.* [NC,OR]

            RewriteCond %{HTTP_USER_AGENT} ^.*chrome* [NC]

            RewriteRule .* - [F]

     </IfModule>

    Apache限制某个目录

    <IfModule mod_rewrite.c>

        RewriteCond %{REQUEST_URI} ^.*/tmp/.* [NC]

        RewriteRule .* - [F]

    </IfModule>

  • 相关阅读:
    Winform中多线程无法访问使用 Control.CheckForIllegalCrossThreadCalls = false;
    PV操作-生产者/消费者关系
    table表格长度超出屏幕范围,可滑动
    Koa2中间件计算响应总耗时/设置响应头/读取Json文件返回给客户端
    Koa2简介和搭建
    计算机浮点数的表示和运算
    CSS实现Loading加载中动画
    RPC
    Git常用命令
    如何解决 shell 脚本重复执行的问题
  • 原文地址:https://www.cnblogs.com/fansik/p/5552182.html
Copyright © 2011-2022 走看看