在服务搭建前,还要了解一下httpd的日志。html
日志有助有工做人员,查看服务器出错情况,更能统计数据分析网页运行状况。web
1)指定错误日志的名称及级别vim
错误日志的路径:/var/log/httpd/error_log浏览器
错误级别: debug, info, notice, warn, error, crit服务器
访问日志: /var/log/httpd/access_logide
[root@wei httpd]# head -n 1 /var/log/httpd/access_log
(2)定义访问日志的格式网站
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combinedspa
192.168.196.1 - - [07/Mar/2019:05:33:39 +0800] "GET / HTTP/1.1" 200 1766 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36"
%h 远端主机
%l 远端登陆名(由identd而来,若是支持的话),除非IdentityCheck设为"On",不然将获得一个"-"。
%u 远程用户名(根据验证信息而来;若是返回status(%s)为401,多是假的)
%t 时间,用普通日志时间格式(标准英语格式)
%r 请求的第一行
%>s:HTTP状态码
%b 以CLF格式显示的除HTTP头之外传送的字节数,也就是当没有字节传送时显示’-'而不是0。
%{Referer}i:记录超连接地址
%{User-Agent}i:记录客户端的浏览器类型debug
(3)指定访问日志的名称及格式rest
CustomLog "logs/access_log" combined
做用:在一台物理服务器上运行多个网站
类型:
基于域名的虚拟主机(经常使用)
基于IP地址的虚拟主机
基于端口的虚拟主机
配置虚拟主机
<VirtualHost 10.1.2.3:80> ServerAdmin webmaster@host.example.com DocumentRoot /www/docs/host.example.com ServerName host.example.com ErrorLog logs/host.example.com-error_log TransferLog logs/host.example.com-access_log </VirtualHost>
www.a.org 网页目录:/var/www/html/a.org 日志:/var/log/httpd/a.org
www.a.org
(1)准备目录
[root@wei ~]# mkdir /var/www/html/a.org [root@wei ~]# vim /var/www/html/a.org/index.html [root@wei ~]# mkdir /var/log/httpd/a.org
(2)编写配置文件
[root@wei ~]# vim /etc/httpd/conf.d/a.org.conf
<VirtualHost 192.168.196.132:80> DocumentRoot /var/www/html/a.org ServerName www.a.org ErrorLog /var/log/httpd/a.org/error_log CustomLog /var/log/httpd/a.org/access_log combined </VirtualHost>
(3)检测配置文件语法
[root@wei ~]# httpd -t
(4)重启服务
[root@wei ~]# systemctl restart httpd