Nginx的ngx_http_gzip_module壓縮模塊提供對文件內容壓縮的功能,容許Nginx服務器將輸出內容在發送客戶端以前進行壓縮,以節約網站帶寬,提高用戶的訪問體驗,默認已經安裝。可在配置文件中加入相應的壓縮功能參數對壓縮性能進行優化。javascript
[root@localhost ~]# systemctl stop firewalld.service //關閉防火牆 [root@localhost ~]# setenforce 0 //關閉加強性安全功能 [root@localhost ~]#
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 6; gzip_types text/plain application/x-javascript text/css image/jpeg image/png image/gif application/xml text/javascript application/x-httpd-php application/javasrcipt application/json; gzip_disable "MSIE [1-6]\."; //IE瀏覽器6版本以上開啓壓縮功能 gzip_vary on; [root@localhost ~]# service nginx restart //重啓服務 [root@localhost ~]#
[root@localhost ~]# mkdir /mnt/tools [root@localhost ~]# mount.cifs //192.168.100.50/tools /mnt/tools/ Password for root@//192.168.100.50/tools: [root@localhost ~]# cp /mnt/tools/forbid.png /usr/local/nginx/html/ //防盜鏈圖片 [root@localhost ~]# cp picture.jpg /usr/local/nginx/html/ //網站圖片 [root@localhost ~]# cd /usr/local/nginx/html/ [root@localhost html]# ls 50x.html forbid.png index.html picture.jpg [root@localhost html]#
[root@localhost html]# vim index.html <h1>Welcome to nginx!</h1> <img src="picture.jpg"/> //添加 [root@localhost html]#
[root@localhost html]# yum install bind -y ..........//省略安裝過程 [root@localhost html]#
[root@localhost html]# vim /etc/named.conf options { listen-on port 53 { any; }; //將127.0.0.1改成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; }; //將localhost改成any [root@localhost html]#
[root@localhost html]# vim /etc/named.rfc1912.zones zone "abc.com" IN { //添加區域 type master; file "abc.com.zone"; allow-update { none; }; }; [root@localhost html]#
[root@localhost html]# 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 abc.com.zone //複製一份模板並重命名 [root@localhost named]# $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.52.131 //添加解析地址 [root@localhost named]# systemctl start named //開啓服務 [root@localhost named]#
<html> <head> <title>盜鏈網站</title> </head> <body> <h1>this is test web</h1> <img src="http:www.abc.com/picture.jpg"/> //盜鏈路徑 </body> </html>
[root@localhost named]# vim /usr/local/nginx/conf/nginx.conf location ~*\.(jpg|gif|swf)$ { valid_referers none blocked *.abc.com abc.com; if ( $invalid_referer ) { rewrite ^/ http://www.abc.com/forbid.png; } } [root@localhost named]# service nginx restart [root@localhost named]#