系统管理 维护监控 简单生活
apache
Apache Don't Log Specific IP Address and User-Agents
十 21st
自cacti 开启通过mod_status对apache 的监控后,apache多了很多监控的访问日志, 对手动分析apache日志,或用awstats分析日志时都需要先对日志进行过滤,一是对监控固定的ip进行日志址滤掉,二是监控访问的固定URL,(awstats也可以过滤掉)先是cat.再grep 然后又是sed ,费时,日志大了还很耗资源.
以关键词"dontlog special ip apache" 找到"setenvif"指令 apache果然可以对特定的url 和或访问IP 不进行日志记录, 详细了解请看:apache 中文手册 (chinaunix)
实现
apache需要装载mod_setenvif模块,可用apachectl -M 命令确认apache是否已装载此模块.如果没有则需要手动编绎一下.可用下面的指令来进行编绎
cd apache_source/modules/metadata /usr/local/apache2/bin/apxs -a -i -c mod_setenvif.c
如下:apachectl -M 已看到apache已成功装载 mod_setenvif
userdir_module (static)
alias_module (static)
so_module (static)
setenvif_module (shared)
打开httpd.conf 文件在合适的位置添加如下内容,
#SetEnvIf Remote_Addr "10\.11\.10\.254" dontlog SetEnvIf Remote_Addr "::1" dontlog SetEnvIf Request_URI "server-status" dontlog
然后修改CustomLog "logs/access_log" combined 为
CustomLog "logs/access_log" combined env=!dontlog
重启apache
可以用tail -f ../logs/access_log 已看不到监控访问的日志了
APACHE配置虚拟主机的三种方法
十 15th
lamp的安装参考: 安装lamp
apache有三种配置虚拟主机的方法,分别是基于不同的端口,不同的IP,和基于不同的域名,这三种方法分别适合不同的场景,
apache2.2以上建义虚拟主机的配置或是修改都在conf/extra/httpd-vhost.conf 文件里进行。然后去掉httpd.conf 里面的 #Include conf/extra/httpd-vhosts.conf 这一行的注释("#" )
针对apache配置文件的修改,都需要重启apache服务
1.基于相同IP不同Port的虚拟主机
更改虚拟主机配置,例如下:
Listen 80 Listen 8888 <VirtualHost *:80> ServerAdmin cacti@realqi.cn DocumentRoot "/usr/local/apache2/htdocs/wordpress/" ServerName develop.realqi.cn DirectoryIndex index.php </VirtualHost> <VirtualHost *:8888> ServerAdmin cacti@realqi.cn DocumentRoot "/usr/local/apache2/htdocs/cms/wordpress" ServerName cms.realqi.cn </VirtualHost>
注意:相关的目录如"wordpress","../cms/wordpress" 必需存在.重启apache,就可生效.
2.基于相同Port不同IP的虚拟主机这种情况适合服务器有多个IP
详细参考:
3.基于域名的虚拟主机的访问,例子如下
NameVirtualHost 10.29.20.22 <VirtualHost www.realqi.cn> ServerAdmin cacti@realqi.cn DocumentRoot "/usr/local/apache2/htdocs/" ServerName www.realqi.cn DirectoryIndex rd.html </VirtualHost> <VirtualHost develop.realqi.cn> ServerAdmin cacti@realqi.cn DocumentRoot "/usr/local/apache2/htdocs/wordpress/" ServerName develop.realqi.cn DirectoryIndex index.php </VirtualHost>
最新评论