在企业中,部署Apache后只能采用默认的配置参数,会引发网站很多的 问题,换言之默认配置是针对以前较低的服务器配置,以前的配置以及不适用现在的互联网时代了。
3.1 gzip介绍
3.2 作用
3.3 Apache实现网页压缩的功能模块包括
Apache 1.x
Apache 2.x
3.4 mod_gzip模块与mod_deflate模块
注:前面就是正常编译安装Apache步骤,但yum多安装zlib-devel(压缩功能);configure配置中多开启一个deflate模块,比之前安装的Apache环境多了个 压缩功能
1.安装Apache
tar zxf apr-1.6.2.tar.gz
tar zxf apr-util-1.6.0.tar.gz
tar jxf httpd-2.4.29.tar.bz2
mv apr-1.6.2 httpd-2.4.29/srclib/apr
mv apr-util-1.6.0 httpd-2.4.29/srclib/apr-util
yum -y install gcc gcc-c++ make pcre-devel expat-devel perl zlib-devel
cd httpd-2.4.29/
./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi --enable-deflate
make && make install
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
vim /etc/init.d/httpd
添加:
#chkconfig:35 85 21
#description:Apache HTTP Server
chkconfig --add httpd
chkconfig --list
ln -s /usr/local/httpd/conf/httpd.conf /etc/
ln -s /usr/local/httpd/bin/* /usr/bin/
vi /etc/httpd.conf
修改:
ServerName www.nb.com:80
systemctl stop firewalld
setenforce 0
[root@server1 ~]# vi /etc/httpd.conf
LoadModule deflate_module/mod_deflate.so #把前面的#删掉,启用mod_deflate模块
[root@server1 ~]# systemctl start httpd
[root@server1 ~]# systemctl status httpd
[root@server1 ~]# netstat -anpt | grep httpd
[root@server1 ~]# apachectl -D DUMP_MODULES | grep deflate
1.设置压缩内容类型
[root@server1 ~]# vi /etc/httpd.conf
#............#在文件末尾加入以下内容
#AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml text/javascript
#DeflateCompressionLevel 9 #9代表压缩等级一般用6即可
#SetOutputFilter DEFLATE text/javascript
DeflateCompressionLevel 9
SetOutputFilter DEFLATE
[root@server1 ~]# systemctl start httpd
[root@server1 ~]# httpd -t
[root@server1 ~]# echo "This is the fa
" > /usr/local/httpd/htdocs/index.html
1.启用网页缓存功能步骤
解决中文乱码的问题
vi /etc/httpd.conf
添加:
AddDefaultCharset utf-8
1.开启expire模块
[root@server1 ~]# vi /etc/httpd.conf
去除#号,开启expire模块
LoadModule expires_module modules/mod_expires.so
[root@server1 ~]# systemctl start httpd
[root@server1 ~]# apachectl -D DUMP_MODULES | grep expires
2.设置配置文件
[root@server1 ~]# vi /etc/httpd.conf
[root@server1 ~]# httpd -t
[root@server1 ~]# systemctl stop httpd
[root@server1 ~]# systemctl start httpd
<IfModule mod_expires.c> 当expire模块开启时,命令生效
ExpiresActive On
ExpiresDefault "access plus 3 day" 缓存3天
</IfModule>
ServerTokens Prod 显示“Server:Apache” 显示版本信息
ServerTokens Major 显示“Server:Apache/2” 版本数
ServerTokens Minor 显示“Server:Apache/2.2” 版本数下发行的版本数
ServerTokens Min 显示“Server:Apache/2.2.17” 完整版本
ServerTokens OS 显示“Server:Apache/2.2.17 (Unix)”平台
ServerTokens Full 显示“Server:Apache/2.2.17 (Unix) PHP/5.3.5”其它平台所有信息(apache嵌存PHP模块)
[root@server1 ~]# vi /usr/local/httpd/conf/extra/httpd-default.conf
修改为:
ServerTokens Prod
[root@server1 ~]# vi /etc/httpd.conf
修改:
Include conf/extra/httpd-default.conf #取消注释
[root@server1 ~]# systemctl stop httpd
[root@server1 ~]# systemctl start httpd
1.删除域名配置
[root@server1 ~]# cd /usr/local/httpd/htdocs/
[root@server1 htdocs]# ls
index.html
[root@server1 htdocs]# rm -rf index.html
[root@server1 htdocs]#
2.编辑配置文件
[root@server1 ~]# vi /etc/httpd.conf
修改:
LoadModule rewrite_module modules/mod_rewrite.so #取消配置
在用本机ip地址访问
重新开一台机器(20.0.0.14)
1.安装httpd,配置域名
[root@server2 ~]# yum -y install httpd
[root@server2 ~]# vi /var/www/html/index.html
添加:
<html><body>Theft<img src="http://20.0.0.13/a.jpg"/></body></html>
[root@server2 ~]# systemctl stop firewalld
[root@server2 ~]# setenforce 0
[root@server2 ~]# systemctl start httpd
在主机上
1.编辑配置文件
[root@server1 ~]# vi /etc/httpd.conf
[root@server1 ~]# httpd -t
[root@server1 ~]# systemctl stop httpd
[root@server1 ~]# systemctl start httpd
AllowOverride All
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://20.0.0.13/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://20.0.0.13/* [NC]
RewriteCond %{HTTP_REFERER} !^http://20.0.0.13$ [NC]
RewriteRule .*\.(gif|jpg|swf)$ http://20.0.0.13/b.png [R,NC]