在企业中,部署Apache后只采用默认的配置参数,会引发网站很多问题,换言之默认配置是针对以前较低的服务器配置的,以前的配置已经不适用当今互联网时代,为了适应企业需求,就需要考虑如何提升Apache的性能与稳定性,这就是Apache优化的内容
apachectl -t -D DUMP_MODULES | grep "deflate"
systemctl stop httpd.service
cd /usr/local/httpd/conf
mv httpd.conf httpd.conf.bak
yum -y install gcc gcc-c++ pcre pcre-devel zlib-devel
cd /opt/httpd-2.4.29/
./configure \
--prefix=/usr/local/httpd \
--enable-so \
--enable-rewrite \
--enable-charset-lite \
--enable-cgi \
--enable-deflate ###加入mod_deflate模块
make [-j2] && make install
vim /usr/local/httpd/conf/httpd.conf
Listen 192.168.230.3:80 ###52行修改
LoadModule deflate_module modules/mod_deflate.so ###105行取消注释,开启mod_deflate模块
ServerName www.xc.com:80 ###199行取消注释,修改
###末行添加以下内容
AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml text/javascript text/jpg text/png ###代表对什么样的内容启用gzip压缩
DeflateCompressionLevel 9 ###代表压缩级别,范围为1~9
SetOutputFilter DEFLATE ###代表启用deflate模块对本站点的输出进行gzip压缩
apachectl -t ###验证配置文件的配置是否正确
apachectl -t -D DUMP_MODULES | grep "deflate" ###检查 mod_deflate模块是否已安装
deflate_module (shared) ###已安装的正确结果
systemctl start httpd.service
cd /usr/local/httpd/htdocs
先将game.jpg文件传到/usr/local/httpd/htdocs目录下
vim index.html
It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!
方法一:
在Linux系统中,打开火狐浏览器,右击点查看元素
选择 网络 ---> 选择 HTML、WS、其他
访问 http://192.168.230.3 ,双击200响应消息查看响应头中包含 Content-Encoding: gzip
方法二:
在Windows系统中依次安装Microsoft.NET4和fiddler软件,打开fiddler 软件
选择 inspectors ---> 选择 Headers
浏览器访问 http://192.168.230.3 ,双击200响应消息查看 Content-Encoding: gzip
apachectl -t -D DUMP_MODULES | grep "expires"
systemctl stop httpd.service
cd /usr/local/httpd/conf
mv httpd.conf httpd.conf.bak1
yum -y install gcc gcc-c++ pcre pcre-devel zlib-devel
cd /opt/httpd-2.4.29/
./configure \
--prefix=/usr/local/httpd \
--enable-so \
--enable-rewrite \
--enable-charset-lite \
--enable-cgi \
--enable-deflate \
--enable-expires ###加入mod_expires模块
make [-j2] && make install
vim /usr/local/httpd/conf/httpd.conf
Listen 192.168.230.3:80 ###52行修改
LoadModule expires_module modules/mod_expires.so ###111行取消注释,开启mod_expires模块
ServerName www.xc.com:80 ###199行取消注释,修改
###末行添加
ExpiresActive On ###打开网页缓存功能
ExpiresDefault "access plus 60 seconds" ###设置缓存60秒
apachectl -t ###验证配置文件的配置是否正确
apachectl -t -D DUMP_MODULES | grep "expires" ###检查 mod_deflate模块是否已安装
deflate_module (shared) ###已安装的正确结果
systemctl start httpd.service
cat /usr/local/httpd/htdocs/index.html
方法一:
在Linux系统中,打开火狐浏览器,右击点查看元素
选择 网络 ---> 选择 HTML、WS、其他
访问 http://192.168.230.3 ,双击200消息查看响应头中包含Expires项
方法二:
在Windows系统中依次安装Microsoft.NET4和fiddler软件,打开fiddler软件
选择 inspectors ---> 选择 Headers
浏览器访问 http://192.168.230.3 ,双击200消息查看Expires项
vim /usr/local/httpd/conf/httpd.conf
Include conf/extra/httpd-default.conf ###491行取消注释
vim /usr/local/httpd/conf/extra/httpd-default.conf
ServerTokens Prod ###55行将原本的Full修改为Prod,只显示名称,没有版本,ServerTokens表示Server回送给客户端的响应头域是否包含关于服务器OS类型和编译过的模块描述信息
systemctl restart httpd.service
浏览器访问 http://192.168.230.3 ,双击200消息查看Server项
apachectl -t -D DUMP_MODULES | grep "rewrite"
systemctl stop httpd.service
cd /usr/local/httpd/conf
mv httpd.conf httpd.conf.bak2
yum -y install gcc gcc-c++ pcre pcre-devel zlib-devel
cd /opt/httpd-2.4.29/
./configure \
--prefix=/usr/local/httpd \
--enable-so \
--enable-rewrite \ ###加入mod_rewrite模块
--enable-charset-lite \
--enable-cgi \
--enable-deflate \
--enable-expires
make [-j2] && make install
vim /usr/local/httpd/conf/httpd.conf
LoadModule rewrite_module modules/mod_rewrite.so ###157行取消注释
###224行,打开rewrite功能,加入mode_rewrite模块内容
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://xc.com/.*$ [NC] ###设置匹配规则
RewriteCond %{HTTP_REFERER} !^http://xc.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.xc.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.xc.com/$ [NC]
RewriteRule .*\.(gif|jpg|swf)$ http://www.xc.com/error.png ###设置跳转动作
RewriteCond %{HTTP_REFERER} !^http://www.xc.com/.*$ [NC]
字段 | 含义 |
---|---|
%{HTTP_REFERER} | 存放一个链接的URL,表示从哪个链接中转访问目录下的静态资源 |
!^ | 表示不以后面的字符串开头 |
http://www.xc.com | 是本网站的路径,按整个字符串匹配 |
.*$ | 表示以任意字符结尾 |
[NC] | 表示不区分大小写字母 |
RewriteRule .*.(gif|jpg|swf)$ http://www.xc.com/error.png
字段 | 含义 |
---|---|
. | 表示匹配一个字符 |
* | 表示匹配0到多个字符,与".“合起来的意思是匹配0到多次前面的任意字符,如果是1到多次匹配可以用”+"表示 |
\. |
在这里的"\" 是转义符,".“就代表符号”.“的意思。因为”."在指令中是属于规则字符,有相应的含义, 如果需要匹配,需要在前面加个转义符"\" ,其它规则字符如果需要匹配,也做同样处理 |
(gif|jpg|swf) | 表示匹配"gif"、“jpg”、“swf"任意一个,”$“表示结束,最后的规则是以”.gif"、“.jpg”、".swf"结尾, 前面是1到多个字符的字符串,也就是匹配图片类型的文件 |
http://www.xc.com/error.png | 表示转发到这个路径 |
注:整个配置的含义是使用本网站以外的网站域名 访问本站的图片文件时,显示error.png这个图片
Web源主机配置:
cd /usr/local/httpd/htdocs
###将game.jpg、error.png文件传到/usr/local/httpd/htdocs目录下
vim index.html
this is xc.com!
echo "192.168.230.3 www.xc.com" >> /etc/hosts
echo "192.168.230.5 www.benet.com" >> /etc/hosts
盗链网站主机:
cd /usr/local/httpd/htdocs ###yum安装的httpd服务的默认路径为/var/www/html/
vim index.html
this is benet.com!
echo "192.168.230.3 www.xc.com" >> /etc/hosts
echo "192.168.230.5 www.benet.com" >> /etc/hosts
http://www.benet.com
tpd服务的默认路径为/var/www/html/
vim index.html
echo “192.168.230.3 www.xc.com” >> /etc/hosts
echo “192.168.230.5 www.benet.com” >> /etc/hosts
#### (5)在盗图网站主机上进行浏览器验证
http://www.benet.com
![在这里插入图片描述](https://img-blog.csdnimg.cn/f968d02aeadf42b39eba01e162720487.png)