您好,登錄后才能下訂單哦!
mod_ expire
模塊配置Apache
,使網(wǎng)頁(yè)能在客戶端瀏覽器緩存一段時(shí)間,以避免重復(fù)請(qǐng)求Expires
標(biāo)簽和Cache-Control
標(biāo)簽,從而降低客戶端的訪問(wèn)頻率和次數(shù),達(dá)到減少不必要的流量和增加訪問(wèn)速度的目的mod_ expire
模塊/usr/local/apache/bin/apachectl -t -D DUMP_MODULES
expires_module (static)
, 則說(shuō)明編譯時(shí)沒(méi)有安裝mod_expires
./configure --enable-expires...
make && make install
httpd.conf
配置文件mod_ expires
模塊, 并設(shè)置http
協(xié)議下任意格式的文檔均60
秒后過(guò)期
<lfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 60 seconds"
</lfModule>
httpd
服務(wù)Apache
服務(wù)時(shí)已經(jīng)安裝過(guò)expires
模塊,這里我直接測(cè)試[root@localhost ~]# vim /usr/local/httpd/conf/httpd.conf
...//省略部分內(nèi)容...
#LoadModule logio_module modules/mod_logio.so
LoadModule env_module modules/mod_env.so
LoadModule expires_module modules/mod_expires.so //找到此模塊,去掉#開(kāi)啟模塊
LoadModule headers_module modules/mod_headers.so
#LoadModule unique_id_module modules/mod_unique_id.so
...//省略部分內(nèi)容...
<IfModule mod_expires.c> //在文件末尾處添加以下條目,對(duì)expires模塊進(jìn)行配置
ExpiresActive On //開(kāi)啟功能
ExpiresDefault" access plus 50 seconds" //設(shè)置緩存時(shí)間
</IfModule>
:wq //保存退出
[root@localhost ~]# apachectl -t //驗(yàn)證語(yǔ)法格式
Syntax OK //語(yǔ)法正常
[root@localhost ~]# service httpd stop //停止HTTP服務(wù)
[root@localhost ~]# service httpd start //啟動(dòng)HTTP服務(wù)
[root@localhost ~]# /usr/local/httpd/bin/apachectl -t -D DUMP_MODULES |grep "expires"
//檢測(cè)模塊是否開(kāi)啟
expires_module (shared) //成功開(kāi)啟
[root@localhost ~]# netstat -ntap | grep 80 //查看端口是否開(kāi)啟
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)
, 則說(shuō)明編譯時(shí)沒(méi)有安裝mod_ rewrite模塊./configure --enable-rewrite...
make && make install
%{HTTP_ REFERER}
: 瀏覽header
中的鏈接字段,存放一-個(gè)鏈接的URL
,代表是從哪個(gè)鏈接訪問(wèn)所需的網(wǎng)頁(yè)!^
:不以后面的字符串開(kāi)頭.*$
: 以任意字符結(jié)尾NC
:不區(qū)分大寫(xiě)R
:強(qiáng)制跳轉(zhuǎn)RewriteEngine On
: 打開(kāi)網(wǎng)頁(yè)重寫(xiě)功能RewriteCond
: 設(shè)置匹配規(guī)則RewriteRule
: 設(shè)置跳轉(zhuǎn)動(dòng)作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
服務(wù),并配置DNS
服務(wù),我們這里是同域名訪問(wèn)網(wǎng)頁(yè);在前面手工編譯安裝Apache
服務(wù)時(shí)已經(jīng)安裝過(guò)放掉連模塊插件mod_rewrite
,直接進(jìn)入HTTP主著配置文件進(jìn)行配置。[root@localhost ~]# yum install bind -y
已加載插件:fastestmirror, langpacks
base | 3.6 kB 00:00
extras | 2.9 kB 00:00
...//省略部分內(nèi)容...
已安裝:
bind.x86_64 32:9.11.4-9.P2.el7
作為依賴被安裝:
bind-export-libs.x86_64 32:9.11.4-9.P2.el7
作為依賴被升級(jí):
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
...//省略部分內(nèi)容...
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; };
...//省略部分內(nèi)容...
:wq
[root@localhost ~]# vim /etc/named.rfc1912.zones
...//省略部分內(nèi)容...
zone "kgc.com" IN {
type master;
file "kgc.com.zone";
allow-update { none; };
};
...//省略部分內(nèi)容...
: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 //啟動(dòng)DNS服務(wù)
[root@localhost ~]# vim /usr/local/httpd/conf/httpd.conf //編輯主配置文件
...//省略部分內(nèi)容...
#LoadModule userdir_module modules/mod_userdir.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so //找到此條,并開(kāi)啟此條目
<IfModule unixd_module>
#
# If you wish httpd to run as a different user or group, you must run
...//省略部分內(nèi)容...
<Directory "/usr/local/httpd/htdocs"> //在此標(biāo)簽下添加防盜鏈條目
#
# 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 //開(kāi)啟防盜鏈功能
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
</Directory>
...//省略部分內(nèi)容...
:wq
[root@localhost ~]# cd /mnt //進(jìn)入掛載目錄
[root@localhost mnt]# ls //查看是否有準(zhǔn)備好的防盜鏈圖片
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/ //將防盜鏈圖片復(fù)制入http站點(diǎn)目錄
[root@localhost mnt]# cd /usr/local/httpd/htdocs/ //進(jìn)入站點(diǎn)目錄
[root@localhost htdocs]# ls //查看
error.png index.html miao.jpg //成功復(fù)制
[root@localhost htdocs]# systemctl start httpd //重啟網(wǎng)絡(luò)服務(wù)
Apache
隱藏版本信息Apache
的版本信息,透露了一定的漏洞信息,從而給網(wǎng)站帶來(lái)安全隱患Apache
隱藏版本信息Fiddler
抓包工具分析Apache
隱藏版本信息將主配置文件httpd.conf
以下行注釋去掉
Include conf/extra/httpd-default.conf
httpd-default.conf
文件兩個(gè)地方ServerTokens Full
修改為Server Tokens Prod
ServersSignature On
修改為ServersSignature Off
[root@localhost htdocs]# vim /usr/local/httpd/conf/httpd.conf
...//省略部分內(nèi)容...
#Include conf/extra/httpd-dav.conf
# Various default settings
Include conf/extra/httpd-default.conf //找到此條目,并去掉注釋
# Configure mod_proxy_html to understand HTML4/XHTML1
<IfModule proxy_html_module>
Include conf/extra/proxy-html.conf
</IfModule>
...//省略部分內(nèi)容...
:wq //保存退出
[root@localhost htdocs]# cd /usr/local/httpd/conf/extra/ //進(jìn)入目錄
[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 //編輯配置文件
...//省略部分內(nèi)容...
# 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 //并確定此處是否為關(guān)閉,默認(rèn)為關(guān)閉
#
# 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 //重啟服務(wù)
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。