1:让 apache 的索引显示支持中文文件和目录
[root@server3 ~]# tail /usr/local/apache2/conf/extra/httpd-vhosts.conf
<VirtualHost 192.168.122.30:80>
DocumentRoot "/home/share"
<Directory /home/share>
Options indexes followsymlinks
order deny,allow
allow from all
</Directory>
ServerName 192.168.122.30
</VirtualHost>
[root@server3 ~]# ls /home/share/
10网段改造问题.txt docs.zip IPVS.doc 中文目录
boot.tgz exam2.JPG putty.exe 数据库
[root@server3 ~]# grep -i 'utf-8' /usr/local/apache2/conf/httpd.conf
AddDefaultCharSet UTF-8
IndexOptions Charset=UTF-8
2:过滤Apache可读取的文件类型,让特定类型的文件不能被访问
root@server3 ~]# grep -A 3 -E '(exe|zip)' /usr/local/apache2/conf/httpd.conf |grep -v '#'
<FilesMatch ".(exe|zip)$">
Order allow,deny
Deny from all
</FilesMatch>
[root@server3 ~]# tail -f /usr/local/apache2/logs/error_log
[Thu May 20 14:44:25 2010] [error] [client 192.168.122.1] client denied by server configuration: /home/share/docs.zip
[Thu May 20 14:44:25 2010] [error] [client 192.168.122.1] client denied by server configuration: /home/share/putty.exe
3:重定向,重定向主要有temp,permanent,gone,seeother四种;
temp:临时重定向,用于文件当前不存在所请求的位置,将来预期会出现在该位置上时的临时重定向
permanent:永久重定向,同temp的情况相反
gone:表示文件不在此位置,以后也不应该再询问了,但gone承认文件曾经存在过,同404错误情况不同,这不会被认为是错误
seeother:告知客户端原始文件已经不存在,并且被不同位置的其他文件所替代
默认情况下,如果没有设定关键字,会使用临时重定向
<VirtualHost 192.168.122.30:80>
DocumentRoot "/home/share"
ServerName 192.168.122.30
Redirect Permanent / http://hi.baidu.com/naruto6006
</VirtualHost>
[root@server3 ~]# tail -f /usr/local/apache2/logs/access_log
192.168.122.1 - - [20/May/2010:15:03:29 +0800] "GET / HTTP/1.1" 301 238
4:apache 查看status和info信息
[root@server3 ~]# grep 'info' /usr/local/apache2/conf/httpd.conf |grep -v '#'
Include conf/extra/httpd-info.conf
[root@server3 ~]# grep -A 5 -E '(status|info)' /usr/local/apache2/conf/extra/httpd-info.conf |grep -v '#' |uniq
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from 192.168.122.60
</Location>
<Location /server-info>
SetHandler server-info
Order deny,allow
Deny from all
Allow from 192.168.122.60
</Location>
5:配置防盗链
第一种方法,使用SetEnvIfNoCase实现
<FilesMatch ".(jpg|jpeg|gif|png)$">
SetEnvIfNoCase Referer "^http://([^/]*.)?yang.com" local_referrer=1
Order Allow,Deny
Allow from env=local_referrer
</FilesMatch>
第二种方法,使用rewrite规则实现
[root@server3 ~]# /usr/local/apache2/bin/apachectl -l |grep rewrite
mod_rewrite.c
《 Apache常见配置精解 》由 第二电脑网 原创提供,转载请注明: http://www.002pc.com/master/College/Server/Apache/17854.html
查看更多关于Apache常见配置精解|root@server3-Apache教程的详细内容...