231321 发表于 2016-3-21 09:49:41

LAMP中apache的相关配置

关于apache的相关配置再次梳理,之前有转载他人的文章。今天把所有的实验都做了,记录一下。方便以后自己使用。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<VirtualHost *:80>
    DocumentRoot "/tmp/tmp"
    ServerName tmp.com
    <Directory /tmp/tmp/>
      Order allow,deny
      Deny from all
    </Directory>
</VirtualHost>


<VirtualHost *:80>
    DocumentRoot "/data/www"
    ServerName www.mydiscuz.com
    ServerAlias www.sunshine.com

##配置过滤指定类型文件以及日志切割------begin
    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

    ErrorLog "|/usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/sunshine.com-error_%Y%m%d_log 86400"
    CustomLog "|/usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/sunshine.com-access_%Y%m%d_log 86400" combined env=!image-request
##配置过滤指定类型文件以及日志切割------end

##配置用户认证------begin
    <Directory /data/www/abc>
      AllowOverride AuthConfig
      AuthName "please input the password..."
      AuthType Basic
      AuthUserFile /data/.htpasswd
      require valid-user
    </Directory>
##配置用户认证------end

##配置域名跳转------begin
    <IfModule mod_rewrite.c>
      RewriteEngine on
      RewriteCond %{HTTP_HOST} ^www.mydiscuz.com$
      RewriteRule ^/(.*)$ http://www.sunshine.com/$1
    </IfModule>
##配置域名跳转------end

##配置静态缓存------begin
    <IfModule mod_expires.c>
      ExpiresActive on
      ExpiresByType image/gif "access plus 1 days"
      ExpiresByType image/jped "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>
##配置静态缓存------end

##关于防盗链的设置------begin
    SetEnvIfNoCase Referer "^http://.*\.sunshine\.com" local_ref
    SetEnvIfNoCase Referer ".*\.sunshine\.com" local_ref
    SetEnvIfNoCase Referer "^$" local_ref
    <filesmatch "\.(txt|doc|mp3|zip|rar|jpg|gif)">
      Order Allow,Deny
      Allow from env=local_ref
    </filesmatch>
##关于防盗链的设置------end

##关于访问控制的配置------begin
    <Directory /data/www/>
      Order deny,allow
      Deny from all
      allow from all
    </Directory>
##关于访问控制的配置------end

##禁止解析php的配置------begin
    <Directory /data/www/data>
      php_admin_flag engine off
      <filesmatch "(.*)php">
            Order deny,allow
            Deny from all
      </filesmatch>
    </Directory>
##禁止解析php的配置------end

##禁止指定user_agent的配置------begin
    <IfModule mod_rewrite.c>
      RewriteEngine on
      RewriteCond %{HTTP_USER_AGENT} ^.*Firefox.*
      RewriteCond %{HTTP_USER_AGENT} ^.*Tomato.*
      RewriteRule .* -
    </IfModule>
##禁止指定user_agent的配置------end

##通过rewrite限制访问某些目录配置------begin
    <IfModule mod_rewrite.c>
      RewriteEngine on
      RewriteCond %{REQUEST_URI} ^.*/tmp/*
      RewriteRule .* -
    </IfModule>
##通过rewrite限制访问某些目录配置------end

</VirtualHost>



页: [1]
查看完整版本: LAMP中apache的相关配置