Apache Virtual host, log polling, log statistics, go to version optimization

Source: Internet
Author: User
Tags ranges apache log

One, the virtual host

1. Domain-based virtual host

Www.zhang.com/var/html/www

Blog.zhang.com/var/html/blog

Bbs.zhang.com/var/html/bbs

#创建虚拟机目录

Mkdir/var/html/{www,blog,bbs}-P

tree/var/html/

/var/html/

├──bbs

├──blog

└──www

#创建默认文件

Touch/var/html/{www,blog,bbs}/index.html

tree/var/html/

/var/html/

├──bbs

│└──index.html

├──blog

│└──index.html

└──www

└──index.html

#写入默认文件内容

For name in www blog bbs;do echo "http:/$name. zhang.com" >/var/html/$name/index.html;done

For name in www blog bbs;do cat/var/html/$name/index.html;done

Http://www.zhang.com

Http://blog.zhang.com

Http://bbs.zhang.com


#配置虚拟站点

Vim/usr/local/httpd/conf/extra/httpd-vhosts.conf

<virtualhost *:80> ServerAdmin [email protected] documentroot "/var/html/www" ServerName www.zhang.com S Erveralias zhang.com errorlog "Logs/www-error_log" Customlog "Logs/www-access_log" common</virtualhost>
<virtualhost *:80> ServerAdmin [email protected] documentroot "/var/html/blog" ServerName blog.zhang.com Serveralias blog.com errorlog "Logs/blog-error_log" Customlog "Logs/blog-access_log" common</VirtualHost>< VirtualHost *:80> ServerAdmin [email protected] documentroot "/var/html/bbs" ServerName bbs.zhang.com Serve Ralias bbs.com errorlog "Logs/bbs-error_log" Customlog "Logs/bbs-access_log" common</virtualhost>


#修改主配置文件加载虚拟站点, remove the comment # number

Vim/usr/local/httpd/conf/httpd.conf

Include Conf/extra/httpd-mpm.confinclude conf/extra/httpd-vhosts.conf


#增加虚拟目录访问权限

Vim/usr/local/httpd/conf/httpd.conf

<directory "/var/html" > Options followsymlinks allowoverride None Require all granted</directory>

#检查配置文件, reload the configuration file

/etc/init.d/httpd-t

Syntax OK

/ETC/INIT.D/HTTPD Graceful


#测试访问站点, note that you need to configure the hosts on the client to configure domain name resolution

Http://www.zhang.com

Http://blog.zhang.com

Http://bbs.zhang.com


2. Port-based virtual host

#在主配置文件中增加端口监听

Vim/usr/local/httpd/conf/httpd.conf

Listen 80Listen 8000Listen 9000

#修改虚拟主机端口号

Vim/usr/local/httpd/conf/extra/httpd-vhosts.conf

<VirtualHost *:80>    ServerAdmin [email protected]     DocumentRoot  "/var/html/www"     ServerName www.zhang.com     ServerAlias zhang.com    ErrorLog  "Logs/www-error_log"      CustomLog  "Logs/www-access_log"  common</VirtualHost><VirtualHost *:8000>     ServerAdmin [email protected]    DocumentRoot  "/var /html/blog "    ServerName blog.zhang.com    ServerAlias  blog.com    errorlog  "Logs/blog-error_log"     CustomLog  " Logs/blog-access_log " common</VirtualHost><VirtualHost *:9000>     serveradmin [email protected]    documentroot  "/var/html/bbs"      ServerName bbs.zhang.com    serveralias bbs.com    errorlog  "logs/ Bbs-error_log "    CustomLog " Logs/bbs-access_log " common</VirtualHost>

#检查配置文件, reload the configuration file

/etc/init.d/httpd-t

Syntax OK

/ETC/INIT.D/HTTPD Graceful


3. IP-based virtual host

Vim/usr/local/httpd/conf/extra/httpd-vhosts.conf

<VirtualHost 10.0.1:80>    ServerAdmin [email protected]     DocumentRoot  "/var/html/www"     ServerName www.zhang.com     ServerAlias zhang.com    ErrorLog  "Logs/www-error_log"      CustomLog  "Logs/www-access_log"  common</VirtualHost><VirtualHost  10.0.2:8000>    serveradmin [email protected]     documentroot  "/var/html/blog"     ServerName blog.zhang.com     ServerAlias blog.com    ErrorLog  "Logs/blog-error_log"      CustomLog  "Logs/blog-access_log"  common</virtualhost><virtualhost 10.0.3:9000 >    ServerAdmin [email protected]    DocumentRoot  " /var/html/bbs "    sErvername bbs.zhang.com    serveralias bbs.com    errorlog   "Logs/bbs-error_log"     CustomLog  "Logs/bbs-access_log"  common</ Virtualhost>


Second, Apache log polling

1. Using Cronolog software to implement log polling

Tar zxvf cronolog-1.6.2.tar.gz

CD cronolog-1.6.2

./configure

Make

Make install

#查看cronolog软件安装路径

Ll/usr/local/sbin/cronolog

-rwxr-xr-x 1 root root 40438 April 22:49/usr/local/sbin/cronolog

#修改虚拟主机日志记录按天使用轮询

Vim/usr/local/httpd/conf/extra/httpd-vhosts.conf

<virtualhost *:9000> ServerAdmin [email protected] documentroot "/var/html/bbs" ServerName bbs.zhang.com Serveralias bbs.com errorlog "Logs/bbs-error_log" Customlog "|/usr/local/sbin/cronolog/usr/local/http/logs/access_ Bbs_%y%m%d.log "combined# Add the above row, the BBS for access to log polling, in days units </VirtualHost>

2. Using Apache to bring your own tools

Vim/usr/local/httpd/conf/extra/httpd-vhosts.conf

<virtualhost *:9000> ServerAdmin [email protected] documentroot "/var/html/bbs" ServerName bbs.zhang.com   Serveralias bbs.com errorlog "|/usr/local/httpd/bin/rotatelogs/usr/local/http/logs/access_bbs_%y%m%d-%h:%m.log 5M" #以大小为单位轮询日志 customlog "|/usr/local/httpd/bin/rotatelogs/usr/local/http/logs/access_bbs_%y%m%d-%h:%m.log 86400" combined# to BBS for access log polling, 86400 for the wonderful number, in days </VirtualHost>

3. Polling log files with shell scripts and timed tasks

cat/usr/local/httpd/logpolling.sh

Cd/usr/local/httpd/logs

MV Www-access_log www-access_$ (date +%f) _log

/usr/local/httpd/bin/apachectl Graceful

echo "0 0 * * */usr/local/httpd/logpolling.sh &>/dev/null" >>/var/spool/cron/root

Third, analysis of the log

#查看访问日志中访问次数最多的ip取最多的10个

awk ' {print '} ' Access_bbs_20170423.log |sort|uniq-c|sort-rn-k1|head-10# ibid ' {++s[$1]} END {for (key in S) print s[ Key],key} ' Access_bbs_20170423.log |sort-rn-k1|head-10

Iv. Modifying hidden version information

1. Change before compiling the installation

Vim/root/tools/httpd-2.4.25/include/ap_release.h

#define Ap_server_basevendor "Apache software Foundation" #define Ap_server_baseproject "Apache HTTP SERVER" #define AP_ Server_baseproduct "Apache" #define Ap_server_majorversion_number 2 #主版本 # define Ap_server_minorversion_number 4 #次版本号 # Define Ap_server_patchlevel_number #define Ap_server_devbuild_boolean 0

Vim/root/tools/httpd-2.4.25/os/unix/os.h

#define PLATFORM "Unix" #运行系统


2, after installation, modify the configuration file, hide version information

Curl-i 10.0.0.4 #查看版本信息

http/1.1 okdate:sun, Apr 15:35:39 gmtserver:apache/2.4.25 (Unix) php/5.6.30last-modified:thu, Apr 2017 1 7:33:10 gmtetag: "15-54d9c88ebe6ed" accept-ranges:bytescontent-length:21content-type:text/html

#去掉版本号

Vim/usr/local/httpd/conf/extra/httpd-default.conf

Servertokens prodserversignature Off

vim/usr/local/httpd/conf/httpd.conf, #去掉前面的注释 #

Include conf/extra/httpd-default.conf

#重新加载配置

.. /bin/apachectl Graceful

#重新查看版本信息

Curl-i 10.0.0.4

http/1.1 okdate:sun, Apr 15:39:10 gmtserver:apache #此次已不再显示版本信息Last-modified:thu, Apr 17:33:10 G Mtetag: "15-54d9c88ebe6ed" accept-ranges:bytescontent-length:21content-type:text/html

This article is from the "Gen Y Rookie" blog, so be sure to keep this source http://zhangxinqi.blog.51cto.com/9668428/1918702

Apache Virtual host, log polling, log statistics, go to version optimization

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.