目录
1.3.1 Apache 自带rotatelogs 分割工具
Apache HTTP Server 之所以受到众多企业的青睐,得益于其代码开源、跨平台、功能 模块化、可灵活定制等诸多优点,不仅性能稳定,在安全性方面的表现也十分出色。
为了更好地控制对网站资源的访问,可以为特定的网站目录添加访问授权。本章将分别介绍客户机地址限制、用户授权限制,这两种访问控制方式都应用于 httpd.conf 配置文件中的目录区域<Directory 目录位置> …… </Directory>范围内。
<Directory "/usr/local/httpd/htdocs">
....... 省略部分内容
Require all granted
</Directory>
<Directory "/usr/local/httpd/htdocs/wwwtest">
...... 省略部分内容
Require ip 172.16.37.148
</Directory>
<Directory "/usr/local/httpd/htdocs/wwwtest">
...... 省略部分内容
<RequireAll>
Require all granted
Require not ip 192.168.0.0/24 192.168.1.0/24
</RequireAll>
</Directory>
[root@www ~]# cd /usr/local/httpd/
[root@www httpd]# bin/htpasswd -c /usr/local/httpd/conf/.awspwd webadmin
New password:
Re-type new password:
Adding password for user webadmin
[root@www httpd]# cat /usr/local/httpd/conf/.awspwd
webadmin:$apr1$puj.M9Bf$ZyAKvsxcx2jKw6GlzqwTK/
[root@www httpd]#
[root@www httpd]# bin/htpasswd /usr/local/httpd/conf/.awspwd zhangsan
New password:
Re-type new password:
Adding password for user zhangsan
[root@www httpd]# cat /usr/local/httpd/conf/.awspwd
webadmin:$apr1$puj.M9Bf$ZyAKvsxcx2jKw6GlzqwTK/
zhangsan:$apr1$krVhdhr3$hzuXofqByQu8APNgeOatK.
[root@www httpd]#
[root@www ~]# vim /usr/local/httpd/conf/httpd.conf …… //省略部分内容
<Directory "/usr/local/httpd/htdocs"> …… //省略部分内容
AuthName "DocumentRoot" AuthType Basic
AuthUserFile /usr/local/httpd/conf/.awspwd
Require valid-user
</Directory>
[root@www ~]# systemctl restart httpd //重启服务使配置生效
所有合法用户,若只授权给单个用户,可改为指定的用户名(如 webadmin)。
[root@www ~]# mkdir /var/log/httpd/
[root@www ~]# vim /usr/local/httpd/conf/httpd.conf
…… //省略部分内容
ErrorLog "|/usr/local/bin/rotatelogs -l /var/log/httpd/error_%Y%m%d.log 86400"
CustomLog "|/usr/local/bin/rotatelogs -l /var/log/httpd/access_%Y%m%d.log 86400" combined
[root@www ~]# systemctl restart httpd
[root@www ~]# ll /var/log/httpd/
总用量 8
-rw-r--r-- 1 root root 150 1 月 11 20:36 access_20200101.log
-rw-r--r-- 1 root root 588 1 月 11 20:35 error_20200101.log
[root@www ~]# tar zxvf cronolog-1.6.2.tar.gz
[root@www ~]# cd cronolog-1.6.2
[root@www cronolog-1.6.2]# ./configure
[root@www cronolog-1.6.2]# make && make install
(2)设置 cronolog 工具工具分割Apache日志
[root@www ~]# vim /usr/local/httpd/conf/httpd.conf
ErrorLog "| /usr/local/sbin/cronolog -l /var/log/httpd/www.bdqn.com-error_%Y%m%d.log 86400"
CustomLog "| /usr/local/sbin/cronolog -l /var/log/httpd/www.bdqn.com-access_%Y%m%d.log 86400" combined
[root@www ~]# systemctl restart httpd.service
[root@www ~]# tar zxf awstats-7.7.tar.gz
[root@www ~]# mv awstats-7.7 /usr/local/awstats
[root@www ~]# cd /usr/local/awstats/tools/
[root@www tools]# ./awstats_configure.pl
----- AWStats awstats_configure 1.0 (build 20140126) (c) Laurent Destailleur -----
This tool will help you to configure AWStats to analyze statistics for
one web server. You can try to use it to let it do all that is possible
in AWStats setup, however following the step by step manual setup
documentation (docs/index.html) is often a better idea. Above all if:
- You are not an administrator user,
- You want to analyze downloaded log files without web server,
- You want to analyze mail or ftp log files instead of web log files,
- You need to analyze load balanced servers log files,
- You want to 'understand' all possible ways to use AWStats...
Read the AWStats documentation (docs/index.html).
-----> Running OS detected: Linux, BSD or Unix
-----> Check for web server install
Enter full config file path of your Web server.
Example: /etc/httpd/httpd.conf
Example: /usr/local/apache2/conf/httpd.conf
Example: c:\Program files\apache group\apache\conf\httpd.conf
Config file path ('none' to skip web server setup):
> /usr/local/httpd/conf/httpd.conf ## 输入httpd.conf配置文件的路径
-----> Need to create a new config file ?
Do you want me to build a new AWStats config/profile
file (required if first install) [y/N] ? y ##确认创建新的站点配置文件
-----> Define config file name to create
What is the name of your web site or profile analysis ?
Example: www.mysite.com
Example: demo
Your web site, virtual server or profile name:
>www.kgc.com ##指定要统计的目标网站名称
-----> Define config file path
In which directory do you plan to store your config file(s) ?
Default: /etc/awstats
Directory path to store config file(s) (Enter for default):
> //直接按 Enter 键接受默认设置
-----> Create config file '/etc/awstats/awstats.www.kgc.com.conf' Config file /etc/awstats/awstats.www.kgc.com.conf created.
...... //省略部分内容
[root@www ~]# vim /usr/local/httpd/conf/httpd.conf
ErrorLog "logs/error_log" CustomLog "logs/access_log" combined
<IfModule !mpm_prefork_module>
LoadModule cgid_module modules/mod_cgid.so
</IfModule>
<IfModule mpm_prefork_module>
LoadModule cgi_module modules/mod_cgi.so
</IfModule>
......
<Directory "/usr/local/awstats/wwwroot">
Options None
AllowOverride None
# Order allow,deny //注释掉
# Allow from all //注释掉
Require all granted //添加
</Directory>
[root@www ~]# systemctl restart httpd
[root@www ~]#vim /etc/awstats/awstats.www.kgc.com.conf
LogFile="/usr/local/httpd/logs/access_log"
DirData="/var/lib/awstats"
…… ## 省略部分内容
[root@www ~]#mkdir /var/lib/awstats
[root@www ~]# cd /usr/local/awstats/tools/
[root@www tools]# chmod +x awstats_updateall.pl
[root@www tools]#./awstats_updateall.pl now
Running '"/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -update
-config=www.kgc.com -configdir="/etc/awstats"' to update config www.kgc.com
Create/Update database for config "/etc/awstats/awstats.www.kgc.com.conf" by
AWStats version 7.7 (build 20180105)
From data in log file "/usr/local/httpd/logs/access_log"... Phase 1 : First bypass old records, searching new record... Searching new records from beginning of log file... Jumped lines in file: 0
Parsed lines in file: 0
Found 0 dropped records, Found 0 comments, Found 0 blank records, Found 0 corrupted records, Found 0 old records, Found 0 new qualified records