您好,登錄后才能下訂單哦!
防盜鏈就是防止別人的網址代碼里面盜用服務器的圖片,文件,視頻等相關資源
如果別人盜用網站的這些靜態資源,明顯的是會增大服務器的帶寬壓力
所以作為網站的維護人員,要杜絕我們服務器的靜態資源被其他網站盜用
%{}HTTP_REFERER}: 瀏覽header中的鏈接字段,存放一個鏈接的URL,代表是從哪個鏈接訪問所需的網頁
!^: 不以后面的字符串開頭
.*$: 以任意字符結尾
NC: 不區分大寫
R:強制跳轉
RewriteEngine On: 打開網頁重寫功能
RewriteCond: 設置匹配規則
RewriteRule: 設置跳轉動作
如果相應變量的值匹配所設置的規則,則逐條向下處理;如果不匹配則往后的規則不在匹配
[root@localhost ~]# yum install bind -y #安裝DNS解析讓實驗更加直觀
已安裝:
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; }; #any
[root@localhost ~]# vim /etc/named.rfc1912.zones
#增加的
zone "kgc.com" IN { #定義域名
type master;
file "kgc.com.zone"; #定義區域數據配置文件
allow-update { none; };
};
[root@localhost named]# cd /var/named/
[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.136.136 #增加一行需要解析的地址
[root@localhost named]# systemctl stop firewalld.service
[root@localhost named]# setenforce 0
[root@localhost named]# systemctl start named
[root@localhost named]# mkdir /chen
[root@localhost named]# mount.cifs //192.168.100.23/LAMP-C7 /chen
Password for root@//192.168.100.23/LAMP-C7:
[root@localhost named]# cd /chen/
[root@localhost chen]# ls
apr-1.6.2.tar.gz Discuz_X2.5_SC_UTF8.zip mysql-5.6.26.tar.gz
apr-util-1.6.0.tar.gz fiddler.exe php-5.6.11.tar.bz2
awstats-7.6.tar.gz httpd-2.4.29.tar.bz2 tu9892_14.jpg
cronolog-1.6.2-14.el7.x86_64.rpm LAMP-php5.6.txt
[root@localhost abc]# tar jxvf httpd-2.4.29.tar.bz2 -C /opt #解壓到OPT底下
[root@localhost abc]# tar zxvf apr-1.6.2.tar.gz -C /opt/
[root@localhost chen]# tar zxvf apr-util-1.6.0.tar.gz -C /opt/
[root@localhost abc]# cd /opt
[root@localhost opt]# ls
apr-1.6.2 apr-util-1.6.0 httpd-2.4.29 rh
[root@localhost opt]# mv apr-1.6.2/ httpd-2.4.29/srclib/apr #移動到這個目錄底下
[root@localhost opt]# mv apr-util-1.6.0/ httpd-2.4.29/srclib/apr-util
[root@localhost opt]# ls
httpd-2.4.29 rh
[root@localhost opt]# cd httpd-2.4.29 /
calhost httpd-2.4.29]#
yum -y install \
gcc \
gcc-c++ \
make \
pcre-devel \
zlib-devel \
expat-devel \
pcre \
perl
./configure \
--prefix=/usr/local/httpd \ #指定路徑
--enable-deflate \ #壓縮功能
--enable-so \ #核心模塊開啟
--enable-rewrite \ #開啟重寫功能,防盜鏈
--enable-charset-lite \ #支持字符集
--enable-cgi#通用網關接口
[root@localhost httpd-2.4.29]# make
[root@localhost httpd-2.4.29]# make install
[root@localhost httpd-2.4.29]# vim /usr/local/httpd/conf/httpd.conf
Listen 192.168.136.136:80
#Listen 80
ServerName www.kgc.com:80
[root@localhost bin]# vim /usr/local/httpd/htdocs/index.html
[root@localhost bin]# cp /chen/tu9892_14.jpg /usr/local/httpd/htdocs/
[root@localhost bin]# ./apachectl start #執行腳本
[root@localhost bin]# netstat -ntap | grep 80 #查看端口
tcp 0 0 192.168.136.136:80 0.0.0.0:* LISTEN 96493/httpd
[root@localhost bin]# vim ../conf/httpd.conf
oadModule rewrite_module modules/mod_rewrite.so #開啟防盜鏈功能
#在249行加入匹配規則
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/wen.png
[root@localhost bin]# cp /chen/wen.png ..//htdocs/
[root@localhost bin]# ls ../htdocs/ #查看一下有沒有這種圖片
index.html tu9892_14.jpg wen.png
[root@localhost bin]# ./apachectl stop
[root@localhost bin]# ./apachectl start
[root@localhost bin]# vim ../conf/httpd.conf
Include conf/extra/httpd-default.conf #開啟隱藏版本號
[root@localhost httpd]# ls
bin cgi-bin error icons lib man modules
build conf htdocs include logs manual
[root@localhost httpd]# cd conf
[root@localhost conf]# ls
extra httpd.conf magic mime.types original
[root@localhost conf]# cd extra/
[root@localhost extra]# ls
httpd-autoindex.conf httpd-languages.conf httpd-ssl.conf
httpd-dav.conf httpd-manual.conf httpd-userdir.conf
httpd-default.conf httpd-mpm.conf httpd-vhosts.conf
httpd-info.conf httpd-multilang-errordoc.conf proxy-html.conf
[root@localhost extra]# vim httpd-default.conf
ServerTokens Prod #原本是版本號的全名,換成Pord
[root@localhost extra]# cd ../../
[root@localhost httpd]# cd bin/
[root@localhost bin]# ./apachectl stop
[root@localhost bin]# ./apachectl start
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。