一、Apache用户认证
1、vim/usr/local/apache2.4/conf/extra/httpd-vhosts.conf//把123.com那个虚拟主机编辑成如下内容
DocumentBoot"/data/wwwroot/www.123.com"
ServerNamewww.123.com
AllowOverrideAuthConfig//这个相当于打开认证的开关
AuthName"123.comuserauth"//自定义认证名字,作用不大
AuthTypeBasic//认证的类型,一般为Basic
AuthUserFile/data/.htpasswd//指定密码文件所在位置
requirevalid-user//指定需要认证的用户为全部可用用户
2、/usr/local/apache2.4/bin/htpasswd-cm/data/.htpasswdlkr1设置登录用户名及密码
3、重新加载配置-t,graceful
4、绑定hosts,浏览器测试
5、curl-x127.0.0.1:80www.123.com//状态码为401
6、curl-x127.0.0.1:80-uaming:passwd(刚才设置的密码)www.123.com//状态码为200
二、Apache访问日志
1、访问日志记录用户的每一个请求
2、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
3、把虚拟主机配置文件改成如下:
DocumentRoot"/data/wwwroot/www.123.com"
ServerNamewww.123.com
ServerAlias123.com
Customlog"logs/123.com-access_log"combined
4、重新加载配置文件-t,graceful
5、curl-x127.0.0.1:80-l123.com
6、tail/usr/local/apache2.4/logs/123.com-access_log