Apache连接保持相关参数
KeepAlive
KeepAliveTimeout
MaxKeepAliveRequests
- 可用<Location>、<Directory>、<Files>、<Limit>配置段中
Require all granted
Require all denied
Require local
Require [not] host <主机名或域名列表>
Require [not] ip <IP地址或网段列表>
'使用not禁止访问时要将其置于 容器中,并在容器中指定相对应的限制策略'
[root@localhost ~]# cd /etc/httpd/conf
[root@localhost conf]# ls
httpd.conf magic
[root@localhost conf]# mkdir extra
[root@localhost conf]# cd extra
[root@localhost extra]# vim vhost.conf
<VirtualHost 20.0.0.47:80>
DocumentRoot "/var/www/html/kevin"
ErrorLog "logs/www.kevin.com.error_log"
CustomLog "logs/www.kevin.com.access_log" common
<Directory> "/var/www/html">
<RequireAll>
Require not ip 20.0.0.50 '表示不允许ip20.0.0.50访问'
Require all granted
</RequireAll>
</Directory>
</VirtualHost>
命令基本格式
'htpasswd命令是httpd自带的'
htpasswd -c /etc/httpd/conf/abc webadmin '为用户webadmin创建密码文件'
New password: '输入密码'
Re-type new password: '重复输入密码'
cat /etc/httpd/conf/abc
webadmin:加密密码
[root@localhost abc]# htpasswd -c /etc/httpd/conf/aaa ddd
New password:
Re-type new password:
Adding password for user ddd
[root@localhost abc]# cat /etc/httpd/conf/aaa
ddd:$apr1$zwIklPGy$ZINaIkXsSq36oIk2lAiiJ1
'添加第二个用户'
[root@localhost abc]# htpasswd /etc/httpd/conf/aaa bbb
New password:
Re-type new password:
Adding password for user bbb
[root@localhost abc]# cat /etc/httpd/conf/aaa
ddd:$apr1$zwIklPGy$ZINaIkXsSq36oIk2lAiiJ1
bbb:$apr1$q7OdS8z1$ELGg2a1AhHP.QfXJXfQTQ1
'配置基本格式'
<Directory "/var/www/html">
AuthName "DocumentRoot" '受保护的领域名称'
AuthType Basic '认证类型'
AuthUserFile /etc/httpd/conf/pwd '用户认证账号文件'
Require valid-user '要求通过认证才能访问'
</Directory>
[root@localhost extra]# vim vhost.conf
<VirtualHost 20.0.0.48:80>
DocumentRoot "/var/www/html/kevin01"
ErrorLog "logs/www.kevin01.com.error_log"
CustomLog "logs/www.kevin01.com.access_log" common
<Directory> "/var/www/html">
AuthName "DocumentRoot"
AuthType basic
AuthUserFile /etc/http/conf/pwd
Require valid-user
</Directory>
</VirtualHost>
ErrorLog "| rotatelogs 命令的绝对路径 -l 日志文件路径/网站名-error_%Y%m%d.log 86400" '//which rotatelogs命令查看绝对路径,%Y%m%d表示年月日,86400表示一天的秒数'
CustomLog "| rotatelogs 命令的绝对路径 -l 日志文件路径/网站名-access_%Y%m%d.log 86400" combined
例如
[root@localhost logs]vim /etc/httpd/conf/httpd.conf
ErrorLog "| /usr/sbin/rotatelogs -l logs/error_%Y%m%d.log 86400"
CustomLog "| /usr/sbin/rotatelogs -l logs/access_%Y%m%d.log 86400" combined
实际生产环境中,一个服务器绝大多数对应N个子域名站点,为了方便统一管理,可以用虚拟主机的方式进行配置,并用网站名标识日志文件
[root@localhost ~]# iptables -F
[root@localhost ~]# setenforce 0
[root@localhost ~]# yum install httpd -y
[root@localhost ~]# which rotatelogs
/usr/sbin/rotatelogs
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
ServerName www.kevin.com:80 '修改域名'
Listen 20.0.0.47:80 '修改监听端口'
#Listen 80 '关闭ipv6监听端口'
[root@localhost ~]# systemctl start httpd.service
[root@localhost ~]# netstat -ntap | grep 80 '查看80端口'
tcp 0 0 20.0.0.47:80 0.0.0.0:* LISTEN 11645/httpd
[root@localhost ~]# ls /var/log/httpd/
access_log error_log
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
'搜索ErrorLog,修改为以下内容'
ErrorLog "| /usr/sbin/rotatelogs -l logs/www.kevin.com.error_%Y%m%d.log 86400"
'搜索CustomLog,修改为以下内容'
CustomLog "| /usr/sbin/rotatelogs -l logs/www.kevin.com.access_%Y%m%d.log 86400" common
[root@localhost ~]# systemctl restart httpd.service
[root@localhost ~]# httpd -t
Syntax OK
[root@localhost ~]# ls /var/log/httpd/
[root@localhost ~]# date -s 09/05/20
2020年 09月 05日 星期六 00:00:00 CST
[root@localhost ~]# ls /var/log/httpd/
access_log www.kevin.com.access_20200805.log www.kevin.com.error_20200805.log
error_log www.kevin.com.access_20200905.log www.kevin.com.error_20200905.log
[root@localhost ~]#cd /opt
cronolog-1.6.2-14.el7.x86_64.rpm '安装cronolog工具'
[root@localhost ~]#rpm -ivh cronolog-1.6.2-14.el7.x86_64.rpm '解压缩工具包'
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
ErrorLog "| /usr/sbin/cronolog logs/www.kevin.com.error_%Y%m%d.log"
CustomLog "| /usr/sbin/cronolog logs/www.kevin.com.access_%Y%m%d.log" combined
[root@localhost opt]# systemctl restart httpd
实验环境
VMware软件
一台centos7虚拟机
一台Windows虚拟机
环境准备
WindowsDNS解析地址指向centos7
centos7安装bind和httpd
[root@localhost opt]# yum install httpd bind -y
[root@localhost opt]# vim /etc/named.conf
options {
listen-on port 53 { any; }; '修改成any'
...省略内容
allow-query { any; }; '修改成any'
[root@localhost opt]# vim /etc/named.rfc1912.zones
zone "kevin.com" IN {
type master;
file "kevin.com.zone";
allow-update { none; };
};
[root@localhost ~]# cd /var/named/
[root@localhost named]# cp -p named.localhost kevin.com.zone
[root@localhost named]# vim kevin.com.zone
www IN A 20.0.0.47
[root@localhost named]# vim /etc/httpd/conf/httpd.conf
ServerName www.kevin.com:80
Listen 20.0.0.47:80
#Listen 80
[root@localhost named]# cd /var/www/html/
[root@localhost html]# vim index.html
<h1>this is test</h1>
[root@localhost html]# systemctl restart named
[root@localhost html]# systemctl restart httpd
[root@localhost html]# iptables -F
[root@localhost html]# setenforce 0
awstats-7.6.tar.gz
[root@localhost html]# mv awstats-7.6.tar.gz /opt
[root@localhost html]# cd /opt/
[root@localhost opt]# tar zxvf awstats-7.6.tar.gz
[root@localhost opt]# mv awstats-7.6 /usr/local/awstats
[root@localhost opt]# cd /usr/local/
[root@localhost local]# cd awstats/tools/
[root@localhost tools]# ./awstats_configure.pl
Config file path ('none' to skip web server setup):
> /etc/httpd/conf/httpd.conf //输入配置文件
> Your web site, virtual server or profile name:
> www.benet.com
> //输入域名
> 其他全部是y或者回车
[root@localhost tools]# vim /etc/httpd/conf/httpd.conf
<Directory "/usr/local/awstats/wwwroot">
Options None
AllowOverride None
# Order allow,deny '注释掉'
# Allow from all gt'注释掉'
Require all granted '添加这行内容'
</Directory>
[root@localhost tools]# cd /etc/awstats/
[root@localhost awstats]# ls
awstats.www.kevin.com.conf
[root@localhost awstats]# vim awstats.www.kevin.com.conf
LogFile= "/var/log/httpd/access log"
//修改访问日志文件位置
DirData=' "/var/lib/awstats"
//awstats默认不存在(需要创建)
[root@localhost awstats]# cd /var/lib/
[root@localhost lib]# mkdir awstats
service httpd restart
[root@localhost tools]# crontab -e
*/5 * * * * /usr/local/awstats/tools/awstats_updateall.pl now
http://20.0.0.51/awstats/awstats.pl?config=www.kevin.com
[root@localhost named]# cd /usr/local/awstats/tools
[root@localhost tools]# ./awstats_updateall.pl now 更新数据
[root@localhost tools]# cd /var/www/html
[root@localhost html]# vim aws.html
<html>
<head>
<meta http-equiv=refresh content= "0;url= http://www.kevin.com/awstats/awstats.pl?config=www.kevin.com">
</head>
<body> </body>
</html>