十周三次课

摘要:摘要: Apache用户认证、域名跳转、 Apache访问日志

1、Apache用户认证

002UASMrzy7605pjKJv15&690.jpg

httpd的用户认证

•还可以针对单个文件进行认证

<VirtualHost*:80>

DocumentRoot"/data/wwwroot/www.123.com"

ServerNamewww.123.com

<FilesMatchadmin.php>

AllowOverrideAuthConfig

AuthName"123.comuserauth"

AuthTypeBasic

AuthUserFile/data/.htpasswd

requirevalid-user

</FilesMatch>

</VirtualHost>

 

 

 


2、域名跳转

•需求,把123.com域名跳转到www.123.com,配置如下:

<VirtualHost*:80>

DocumentRoot"/data/wwwroot/www.123.com"

ServerNamewww.123.com

ServerAlias123.com

<IfModulemod_rewrite.c>//需要mod_rewrite模块支持

RewriteEngineon//打开rewrite功能

RewriteCond%{HTTP_HOST}!^www.123.com$//定义rewrite的条件,主机名(域名)不是www.123.com满足条件

RewriteRule^/(.*)$http://www.123.com/$1[R=301,L]//定义rewrite规则,当满足上面的条件时,这条规则才会执行

</IfModule>

</VirtualHost>

•/usr/local/apache2/bin/apachectl-M|grep-irewrite//若无该模块,需要编辑配置文件httpd.conf,删除rewrite_module(shared)前面的#

•curl-x127.0.0.1:80-I123.com//状态码为301

 

 


3、Apache访问日志

•访问日志记录用户的每一个请求

•vim/usr/local/apache2.4/conf/httpd.conf//搜索LogFormat

LogFormat"%h%l%u%t"%r"%>s%b"%{Referer}i""%{User-Agent}i""combined

LogFormat"%h%l%u%t"%r"%>s%b"common

•把虚拟主机配置文件改成如下:

<VirtualHost*:80>

DocumentRoot"/data/wwwroot/www.123.com"

ServerNamewww.123.com

ServerAlias123.com

CustomLog"logs/123.com-access_log"combined

</VirtualHost>

•重新加载配置文件-t,graceful

•curl-x127.0.0.1:80-I123.com

•tail/usr/local/apache2.4/logs/123.com-access_log