标签:
//apache 的网站配置文件 /usr/local/apache2/conf/extra/httpd-vhosts.conf -->在编辑这个文件前需要去httpd.conf把这个文件的注释去掉 <VirtualHost *:80> DocumentRoot "/data/www" ServerName www.123.com #不记录指定文件的日志 --还要加上env 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/aaa-error_%Y%m%d.log 86400" CustomLog "|/usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/aaa-access_%Y%m%d.log 86400"combined env=!image-request #301跳转 <IfModule mod_rewrite.c> RewriteEngine on #进入下列网站 RewriteCond %{HTTP_HOST} ^www.tiaozhuan.com [OR] RewriteCond %{HTTP_HOST} ^www.test.com$ #都跳转到www.123.com RewriteRule ^/(.*)$ http://www.123.com/$1 [R=301,L] #禁止user_agent NC为不区分大小写 OR代表二者取一 全部都取就不要OR Rule为规则-F所有访问拒绝 RewriteCond %(HTTP_USER_AGENT} ^Mozilla/5.* [NC] RewriteCond %(HTTP_USER_AGENT} ^.*chrome* [NC] RewriteRule .* - [F] #限制某一个目录不让用户访问,也可利用deny和allow进行限制 RewriteCond %{REQUEST_URI} ^.*/tmp/.* [NC] RewriteRule .* - [F] </IfModule> #静态缓存 #1.mod_expires.c <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-javacript "now plus 2 hours" ExpiresByType application/javascript "now plus 2 hours" ExpiresByType application/x-shockwave-flash "now plus 2 hours" ExpiresDefault "now plus 2 hours" </IfModule> #访问控制 <Directory /data/www/> Order deny,allow Deny from all Allow from 127.0.0.1 </Directory> #针对请求的URI限制 #<filesmatch "(.*)admin(.*)"> # Order deny,allow # Deny from all # Allow from 127.0.0.1 # </filesmatch> #全部PASS #<Directory> #Order deny,allow #全部NOT PASS #<Directory> #Order allow,deny #针对网站的用户上传的文件进行限制php解析 <Directory /data/www/data> php_admin_flag engine off <filesmatch "(.*)php"> Order deny,allow Deny from all Allow from 127.0.0.1 </filesmatch> </Directory> #防盗链 SetEnvIfNoCase Referer "^htt://.*\baidu\.com" local_ref SetEnvIfNoCase Referer "^htt://.*\sohu\.com" local_ref SetEnvIfNoCase Referer "^$"" local_ref <filesmatch "\.(txt|doc|mp3|zip|rar|jpg|gif|png)"> Order Allow,Deny Allow from env=local_ref </filesmatch> </VirtualHost> #2.mod_headers #<IfModule mod_headers.c> #htm,html,txt类的文件缓存 存放一个小时 # <filematch "\.(htmlhtm|txt)$"> #header set cache-control "max-age=3600" # </filematch>
写配置文件会遇到的错误 :
1.
/usr/local/apache2/bin/apachectl -t
Syntax error on line 34 of /usr/local/apache2/conf/extra/httpd-vhosts.conf:
AuthUserFile takes 1-2 arguments, text file containing user IDs and passwords
1.因为 多出了 AllowOverride AuthConfig
2. 34行有中文注释,将其删除即可
标签:
原文地址:http://www.cnblogs.com/frankielf0921/p/5374229.html