Apache配置
DNS配置
清空防火墙规则,关闭核心防护
iptables -F
setenforce 0
安装环境包
yum -y install bind httpd
修改主配置文件
vim /etc/named.conf
13 listen-on port 53 { any; };
21 allow-query { any; };
修改区域配置文件
vim /etc/named.rfc1912.zones
zone "hewei.com" IN {
type master;
file "hewei.com.zone";
allow-update { none; };
};
修改数字区域配置文件
cd /var/named/
cp -p named.localhost hewei.com.zone
vim hewei.com.zone
www IN A 192.168.174.155
启动DNS服务
systemctl start named
日志分割
安装环境包
cd /opt
rpm -ivh cronolog-1.6.2-14.el7.x86_64.rpm
修改主配置文件,修改结果如下
vim /etc/httpd/conf/httpd.conf
182 # ErrorLog "| /usr/sbin/rotatelogs -l logs/www.hewei.com.error_%Y%m%d.log 86400"
183 ErrorLog "| /usr/sbin/cronolog logs/www.hewei.com.error_%Y%m%d.log"
184 #ErrorLog "logs/error_log"
219 #CustomLog "logs/access_log" combined
220 # CustomLog "| /usr/sbin/rotatelogs -l logs/www.hewei.com.access_%Y%m%d.log 86400" combined
221 CustomLog "| /usr/sbin/cronolog logs/www.hewei.com.access_%Y%m%d.log" combi ned
设置网页内容
vim /var/www/html/index.html
<h1>大爷,上来玩啊</h1>
搭建AWStats日志分析系统
解压缩包
cd /opt
tar zxvf awstats-7.6.tar.gz
tar zxvf apr-util-1.6.0.tar.gz
tar jxvf httpd-2.4.29.tar.bz2
tar zxvf apr-1.6.2.tar.gz
mv /opt/awstats-7.6 /usr/local/awstats
mv apr-1.6.2 httpd-2.4.29/srclib/apr
mv apr-util-1.6.0 httpd-2.4.29/srclib/apr-util
设置管理
cd /usr/local/awstats/tools
./awstats_configure.pl
Config file path ('none' to skip web server setup):
> /etc/httpd/conf/httpd.conf
y
Your web site, virtual server or profile name:
> www.hewei.com
接下来3次回车,完成退出
修改配置文件
vim /etc/httpd/conf/httpd.conf
<Directory "/usr/local/awstats/wwwroot">
Options None
AllowOverride None
#Order allow,deny
#Allow from all
Require all granted
</Directory>
修改文件
cd /etc/awstats/
vim awstats.www.hewei.com.conf
第50行更改如下
50 LogFile="/var/log/httpd/access_log"
:wq
创建目录
cd /var/lib/
mkdir awstats
启动httpd服务
service httpd restart
开启实时监测
cd /usr/local/awstats/tools/
./awstats_updateall.pl now
crontab -e
*/5 * * * * /usr/local/awstats/tools/awstats_updateall.pl now
打开网页
http://www.hewei.com/awstats/awstats.pl?config=www.hewei.com
实现gzip压缩功能
安装环境包
yum -y install gcc gcc-c++ make pcre-devel expat-devel perl
yum -y install zlib-devel
配置
cd httpd-2.4.29
./configure \
--prefix=/usr/local/httpd \
--enable-deflate \
--enable-expires \
--enable-so \
--enable-rewrite \
--enable-charset-lite \
--enable-cgi
编译安装
make && make install
修改httpd的配置文件,开启3个核心模块
vim /usr/local/httpd/conf/httpd.conf
分别在101行,105行,112行,将#去掉,如下
101 LoadModule filter_module modules/mod_filter.so
105 LoadModule deflate_module modules/mod_deflate.so
112 LoadModule headers_module modules/mod_headers.so
更改198行,如下
198 ServerName www.hewei.com:80
更改51,52行,如下
51 Listen 192.168.174.155:80
52 #Listen 80
在末行添加配置,允许图片的添加
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript text/jpg text/png
DeflateCompressionLevel 9
#ExpiresActive On
#ExpiresDefault "access plus 50 seconds"
SetOutputFilter DEFLATE
</IfModule>
退出后,输入如下命令,回车启动
/usr/local/httpd/bin/httpd
启动Apache
cd /usr/sbin
./apachectl
./apachectl -t -D DUMP_MODULES | grep "deflate"
添加图片
cd /usr/local/httpd/htdocs/
拉一张图片进去
我这边图片名是333.png
vim /var/www/html/index.html
添加
<h1>大爷,上来玩啊</h1>
<img src="333.png"/>
压缩域名
cd /var/www/html
vim aws.html
<html>
<head>
<meta http-equiv=refresh content="0;url=http://www.hewei.com/awstats/awstats.pl?config=www.hewei.com">
</head>
<body></body>
</html>
:wq
隐藏Apache版本号
[root@localhost html]# vim /etc/httpd/conf/httpd.conf
在末尾插入两行内容:
ServerTokens Prod
ServerSignature off
防盗链
我们再创建一个新的主机,用于盗链
并进行相关监听配置
vim /etc/httpd/conf/httpd.conf
修改51、52、198行中的监听地址、端口及域名信息
然后我们开始创建盗链网页
[root@daolian ~]# vim /var/www/html/index.html
<h1>dao</h1>
<img src="http://www.hewei.com/333.jpg">
接下来我们添加DNS服务器地址到盗链服务器上
echo "nameserver 192.168.174.155" > /etc/resolv.conf
systemctl restart httpd
接下来,我们进行防盗链操作
[root@server bin]# vim /etc/httpd.conf
将156行前面的#去掉
156 LoadModule rewrite_module modules/mod_rewrite.so
在<Directory "/usr/local/httpd/htdocs">内添加防盗链规则,如下
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://test.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://test.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.test.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.test.com/$ [NC]
RewriteRule .*\.(gif|jpg|swf)$ http://www.test.com/error.png
添加防盗链图片
cd /usr/local/httpd/htdocs/
进入这个目录,添加一张222.png的图片,作为发生盗链情况,自动显示该图片
启动
cd /usr/local/httpd/bin/
/apachectl stop
/apachectl start