本文共 4005 字,大约阅读时间需要 13 分钟。
目录
访问web服务,本质上看(从协议上)是访问某个IP的主机上的某个端口(默认是80)通常需要通过访问不同的域名或者端口实现对不同网站的访问(具体到服务器里就是不同目录),这个时候就需要设置虚拟主机(VirtualHost).通常分为这样3种:
基于域名,基于端口,基于IP,以及它们的混合。
在linux下的日志会定期进行滚动增加,我们可以在线对正在进行回滚的日志进行指定大小的 切割(动态)
如果这个日志是静态的。比如没有应用向里面写内容。那么我们也可以用split工具进行切割; 其中Logrotate支持按时间和大小来自动切分,以防止日志文件太大。 真正内容:当日志达到某个特定的大小,我们将日志分类,之前的日志保留一个备份,再产生的日志创建一个同名的文件保存新的日志。#配置域名信息echo "192.168.1.21 www.accp.com www.benet.com" >> /etc/hosts#配置index.htmlmkdir -p /var/www/html/accpmkdir -p /var/www/html/benetecho "www.accp.com
" /var/www/html/accp/index.htmlecho "www.benet.com
" /var/www/html/benet/index.html
#将此注释去掉,让其加载httpd-vhosts.conf文件Include conf/extra/httpd-vhosts.conf
#在/usr/local/httpd/conf/extra路径下,修改httpd-vhost.conf文件#设置不同域名访问DocumentRoot "/var/www/html/accp" ServerName www.accp.com ErrorLog "logs/accp.com-error.log" CustomLog "|/usr/sbin/cronolog /var/log/httpd/access_accp_log_%Y%m%d.log" combined DocumentRoot "/var/www/html/benet" ServerName www.benet.com ErrorLog "logs/benet.com-error.log" CustomLog "|/usr/sbin/cronolog /var/log/httpd/access_benet_%Y%m%d.log" combined Options None AllowOverride None Require all granted
ifconfig ens33:0 192.168.1.100 netmask 255.255.255.0
#设置不同ip访问DocumentRoot "/var/www/html/accp" ServerName www.accp.com ErrorLog "logs/accp.com-error.log" CustomLog "|/usr/sbin/cronolog /var/log/httpd/access_accp_log_%Y%m%d.log" combined DocumentRoot "/var/www/html/benet" ServerName www.benet.com ErrorLog "logs/benet.com-error.log" CustomLog "|/usr/sbin/cronolog /var/log/httpd/access_benet_%Y%m%d.log" combined Options None AllowOverride None Require all granted
#修改httpd.conf 中,添加一条监听对象Listen 192.168.1.21:80Listen 192.168.1.100:80
httpd -t#如果httpd -t 为seccssulf则执行重启systemctl stop httpdsystemctl start httpd
#设置不同端口访问DocumentRoot "/var/www/html/accp" ServerName www.accp.com ErrorLog "logs/accp.com-error.log" CustomLog "|/usr/sbin/cronolog /var/log/httpd/access_accp_log_%Y%m%d.log" combined DocumentRoot "/var/www/html/benet" ServerName www.benet.com ErrorLog "logs/benet.com-error.log" CustomLog "|/usr/sbin/cronolog /var/log/httpd/access_benet_%Y%m%d.log" combined Options None AllowOverride None Require all granted
#修改httpd.conf 中,添加一条监听对象Listen 192.168.1.21:80Listen 192.168.1.21:8080
httpd -t#如果httpd -t 为seccssulf则执行重启systemctl stop httpdsystemctl start httpd
日志分割此处两个个方法,一个是系统自带的rotatelogs简单的日志分割工具,一个是外部第三方下载的cronolog日志管理工具,此处,本人配置了两种,请看步骤
注:如果需要在主配置(httpd.conf)进行做全局配置,那么就需要将读取httpd-vhost.conf的选项在配置文件中注释掉,不然会出现access日志文件不生成的问题。
此处按照每个虚拟主机的来进行日志分割
配置httpd-vhost.conf文件
#在每个虚拟主机配置中进行添加# ErrorLog "| /usr/local/bin/rotatelogs -l /var/log/httpd/error_log_%Y%m%d.log 86400"# CustomLog "|/usr/local/bin/rotatelogs -l /var/log/httpd/access_accp_log_%Y%m%d.log"#当然日志命名可以根据你的需要更改DocumentRoot "/var/www/html/accp" ServerName www.accp.com ErrorLog "logs/accp.com-error.log" ErrorLog "| /usr/local/bin/rotatelogs -l /var/log/httpd/error_log_%Y%m%d.log 86400" CustomLog "|/usr/local/bin/rotatelogs -l /var/log/httpd/access_accp_log_%Y%m%d.log" combined DocumentRoot "/var/www/html/benet" ServerName www.benet.com ErrorLog "logs/benet.com-error.log" ErrorLog "| /usr/local/bin/rotatelogs -l /var/log/httpd/error_log_%Y%m%d.log 86400" CustomLog "|/usr/local/bin/rotatelogs -l /var/log/httpd/access_benet_%Y%m%d.log" combined Options None AllowOverride None Require all granted
yum -y install cronolog
只需要将/usr/local/bin/rotatelogs 修改为 /usr/sbin/cronolog 即可.
1.虚拟机主机就是对域名、端口、ip地址进行设置,主要是修改httpd.conf和httpd-vhost.conf文件。
2.日志分割这块,其实有很多工具可以进行分割,此处使用了两种,但在使用方面都是很相近的。
转载地址:http://pwucn.baihongyu.com/