Apache相关配置

回复 收藏
配置文件: /usr/local/apache2/conf/extra/httpd-vhosts.conf

设置静态缓存

ExpiresActive on
ExpiresByType image/gif "access plus 1 days"
ExpiresByType image/jpeg "access plus 24 hour"
ExpiresByType image/png "access plus 24 hour"
ExpiresByType image/css "now plus 2 hour"
ExpiresByType application/x-javascritpt "now plus 1 hour"
ExpiresByType application/x-shockwave-flash "now plus 1 hour"
ExpiresDefault "now plus 0 min"


301重定向

        RewriteEngine on
        RewriteCond %{HTTP_HOST} ^www.aaa.com$ [OR]
  RewriteCond %{HTTP_HOST} ^www.bbb.com$
        RewriteRule ^/(.*)$ http://www.test.com/$1 [R=301,L]
  RewriteCond %{HTTP_USER_AGENT} ^.*curl.* [NC,OR]
  RewriteCond %{HTTP_USER_AGENT} ^.*chrome* [NC]
  RewriteRule .* - [F]
RewriteCond %{REQUEST_URI} ^.*/tmp/.* [NC]
  RewirteRule .* - [F]
   

指定类型文件不记录日志
    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
    SetEnvIf Request_URI ".*\.jpeg$" image-request
    ErrorLog "|/usr/local/apache2/bin/rotatelogs -l                 /usr/local/apapche2/logs/test.com-error_%Y%m%d.log 86400"
    CustomLog "|/usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/test.com-access_%Y%m%d.log 86400" combined env=!image-request

访问控制

        AllowOverride AuthConfig
        AuthName "My DRV"
        AuthType Basic
        AuthUserFile /data/.htpasswd
        require valid-user
   

限制IP访问

        AllowOverride None
        options None
        Order allow,deny
        Allow from All
        Deny from 192.168.1.102
      


        Order deny,allow
        Allow from 127.0.0.1
        Deny from all


禁止解析PHP

php_admin_flag engine off

order deny,allow
Deny from all
Allow from 127.0.0.1



虚拟机配置文件示例
------------------------------------------------------------------------------
#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
#
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any  block.
#

   DocumentRoot "/tmp/ccc"
   ServerName 1111.com

    DocumentRoot "/data/www"
    ServerName www.test.com
    ServerAlias www.aaa.com

   
        AllowOverride None
        options None
        Order allow,deny
        Allow from All
        Deny from 192.168.1.102
   
        Order deny,allow
        Allow from 127.0.0.1
        Deny from all
   

    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
    SetEnvIf Request_URI ".*\.jpeg$" image-request
    ErrorLog "|/usr/local/apache2/bin/rotatelogs -l /usr/local/apapche2/logs/test.com-error_%Y%m%d.log 86400"
    CustomLog "|/usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/test.com-access_%Y%m%d.log 86400" combined env=!image-request
   
        RewriteEngine on
        RewriteCond %{HTTP_HOST} ^www.aaa.com$
        RewriteRule ^/(.*)$ http://www.test.com/$1 [R=301,L]
   
        ExpiresActive on
        ExpiresByType image/gif "access plus 1 days"
        ExpiresByType image/jpeg "access plus 24 hour"
        ExpiresByType image/png "access plus 24 hour"
        ExpiresByType image/css "now plus 2 hour"
        ExpiresByType application/x-javascritpt "now plus 1 hour"
        ExpiresByType application/x-shockwave-flash "now plus 1 hour"
        ExpiresDefault "now plus 0 min"
   
        AllowOverride AuthConfig
        AuthName "My DRV"
        AuthType Basic
        AuthUserFile /data/.htpasswd
        require valid-user
   
2016-08-21 22:06 举报
已邀请:
0

lipengfei1

赞同来自:

学习了{:4_106:}

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: