十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
mod_ expire
模块配置Apache
,使网页能在客户端浏览器缓存一段时间,以避免重复请求Expires
标签和Cache-Control
标签,从而降低客户端的访问频率和次数,达到减少不必要的流量和增加访问速度的目的mod_ expire
模块/usr/local/apache/bin/apachectl -t -D DUMP_MODULES
expires_module (static)
, 则说明编译时没有安装mod_expires
./configure --enable-expires...
make && make install
httpd.conf
配置文件mod_ expires
模块, 并设置http
协议下任意格式的文档均60
秒后过期
<lfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 60 seconds"
</lfModule>
httpd
服务Apache
服务时已经安装过expires
模块,这里我直接测试[root@localhost ~]# vim /usr/local/httpd/conf/httpd.conf
...//省略部分内容...
#LoadModule logio_module modules/mod_logio.so
LoadModule env_module modules/mod_env.so
LoadModule expires_module modules/mod_expires.so //找到此模块,去掉#开启模块
LoadModule headers_module modules/mod_headers.so
#LoadModule unique_id_module modules/mod_unique_id.so
...//省略部分内容...
//在文件末尾处添加以下条目,对expires模块进行配置
ExpiresActive On //开启功能
ExpiresDefault" access plus 50 seconds" //设置缓存时间
:wq //保存退出
[root@localhost ~]# apachectl -t //验证语法格式
Syntax OK //语法正常
[root@localhost ~]# service httpd stop //停止HTTP服务
[root@localhost ~]# service httpd start //启动HTTP服务
[root@localhost ~]# /usr/local/httpd/bin/apachectl -t -D DUMP_MODULES |grep "expires"
//检测模块是否开启
expires_module (shared) //成功开启
[root@localhost ~]# netstat -ntap | grep 80 //查看端口是否开启
tcp 0 0 192.168.144.133:80 0.0.0.0:* LISTEN 47752/httpd
检查Apache
是否安装了mod_rewrite
模块
十年建站经验, 成都网站设计、网站制作客户的见证与正确选择。成都创新互联公司提供完善的营销型网页建站明细报价表。后期开发更加便捷高效,我们致力于追求更美、更快、更规范。
/usr/local/apache/bin/apachectl -t -D DUMP_ MODULES
rewrite_module (static)
, 则说明编译时没有安装mod_ rewrite模块./configure --enable-rewrite...
make && make install
%{HTTP_ REFERER}
: 浏览header
中的链接字段,存放一-个链接的URL
,代表是从哪个链接访问所需的网页!^
:不以后面的字符串开头.*$
: 以任意字符结尾NC
:不区分大写R
:强制跳转RewriteEngine On
: 打开网页重写功能RewriteCond
: 设置匹配规则RewriteRule
: 设置跳转动作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 .*\.(gifljipg|swf)$ http://www.test.com/error.html [R,NC]
DNS
服务,并配置DNS
服务,我们这里是同域名访问网页;在前面手工编译安装Apache
服务时已经安装过放掉连模块插件mod_rewrite
,直接进入HTTP主著配置文件进行配置。[root@localhost ~]# yum install bind -y
已加载插件:fastestmirror, langpacks
base | 3.6 kB 00:00
extras | 2.9 kB 00:00
...//省略部分内容...
已安装:
bind.x86_64 32:9.11.4-9.P2.el7
作为依赖被安装:
bind-export-libs.x86_64 32:9.11.4-9.P2.el7
作为依赖被升级:
bind-libs.x86_64 32:9.11.4-9.P2.el7
bind-libs-lite.x86_64 32:9.11.4-9.P2.el7
bind-license.noarch 32:9.11.4-9.P2.el7
bind-utils.x86_64 32:9.11.4-9.P2.el7
dhclient.x86_64 12:4.2.5-77.el7.centos
dhcp-common.x86_64 12:4.2.5-77.el7.centos
dhcp-libs.x86_64 12:4.2.5-77.el7.centos
完毕!
[root@localhost ~]# vim /etc/named.conf
...//省略部分内容...
options {
listen-on port 53 { any; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
recursing-file "/var/named/data/named.recursing";
secroots-file "/var/named/data/named.secroots";
allow-query { any; };
...//省略部分内容...
:wq
[root@localhost ~]# vim /etc/named.rfc1912.zones
...//省略部分内容...
zone "kgc.com" IN {
type master;
file "kgc.com.zone";
allow-update { none; };
};
...//省略部分内容...
:wq
[root@localhost ~]# cd /var/named/
[root@localhost named]# ls
data dynamic named.ca named.empty named.localhost named.loopback slaves
[root@localhost named]# cp -p named.localhost kgc.com.zone
[root@localhost named]# vim kgc.com.zone
$TTL 1D
@ IN SOA @ rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
A 127.0.0.1
www IN A 192.168.144.133
[root@localhost named]# systemctl start named //启动DNS服务
[root@localhost ~]# vim /usr/local/httpd/conf/httpd.conf //编辑主配置文件
...//省略部分内容...
#LoadModule userdir_module modules/mod_userdir.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so //找到此条,并开启此条目
#
# If you wish httpd to run as a different user or group, you must run
...//省略部分内容...
//在此标签下添加防盗链条目
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
Require all granted
RewriteEngine On //开启防盗链功能
RewriteCond %{HTTP_REFERER} !^http://kgc.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://kgc.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.kgc.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http:// www.kgc.com/$ [NC]
RewriteRule .*\.(gif|jpg|swf)$ http://www.kgc.com/error.png
...//省略部分内容...
:wq
[root@localhost ~]# cd /mnt //进入挂载目录
[root@localhost mnt]# ls //查看是否有准备好的防盗链图片
apr-1.6.2.tar.gz cronolog-1.6.2-14.el7.x86_64.rpm httpd-2.4.29.tar.bz2 MySQL-5.6.26.tar.gz
apr-util-1.6.0.tar.gz Discuz_X2.5_SC_UTF8.zip LAMP-php5.6.txt nginx-1.12.0.tar.gz
awstats-7.6.tar.gz error.png miao.jpg php-5.6.11.tar.bz2
[root@localhost mnt]# cp error.png /usr/local/httpd/htdocs/ //将防盗链图片复制入http站点目录
[root@localhost mnt]# cd /usr/local/httpd/htdocs/ //进入站点目录
[root@localhost htdocs]# ls //查看
error.png index.html miao.jpg //成功复制
[root@localhost htdocs]# systemctl start httpd //重启网络服务
Apache
隐藏版本信息Apache
的版本信息,透露了一定的漏洞信息,从而给网站带来安全隐患Apache
隐藏版本信息Fiddler
抓包工具分析Apache
隐藏版本信息将主配置文件httpd.conf
以下行注释去掉
Include conf/extra/httpd-default.conf
httpd-default.conf
文件两个地方ServerTokens Full
修改为Server Tokens Prod
ServersSignature On
修改为ServersSignature Off
[root@localhost htdocs]# vim /usr/local/httpd/conf/httpd.conf
...//省略部分内容...
#Include conf/extra/httpd-dav.conf
# Various default settings
Include conf/extra/httpd-default.conf //找到此条目,并去掉注释
# Configure mod_proxy_html to understand HTML4/XHTML1
Include conf/extra/proxy-html.conf
...//省略部分内容...
:wq //保存退出
[root@localhost htdocs]# cd /usr/local/httpd/conf/extra/ //进入目录
[root@localhost extra]# ls
httpd-autoindex.conf httpd-info.conf httpd-mpm.conf httpd-userdir.conf
httpd-dav.conf httpd-languages.conf httpd-multilang-errordoc.conf httpd-vhosts.conf
httpd-default.conf httpd-manual.conf httpd-ssl.conf proxy-html.conf
[root@localhost extra]# vim httpd-default.conf //编辑配置文件
...//省略部分内容...
# Set to one of: Full | OS | Minor | Minimal | Major | Prod
# where Full conveys the most information, and Prod the least.
#
ServerTokens Prod //找到此条目,并更改Full为Prod
#
# Optionally add a line containing the server version and virtual host
# name to server-generated pages (internal error documents, FTP directory
# listings, mod_status and mod_info output etc., but not CGI generated
# documents or custom error documents).
# Set to "EMail" to also include a mailto: link to the ServerAdmin.
# Set to one of: On | Off | EMail
#
ServerSignature Off //并确定此处是否为关闭,默认为关闭
#
# HostnameLookups: Log the names of clients or just their IP addresses
# e.g., www.apache.org (on) or 204.62.129.132 (off).
:wq //保存退出
[root@localhost extra]# systemctl restart httpd.service //重启服务