Nginx的ngx_http_gzip_module压缩模块提供对文件内容压缩的功能,允许Nginx服务器将输出内容在发送客户端之前进行压缩,以节约网站带宽,提升用户的访问体验,默认已经安装。可在配置文件中加入相应的压缩功能参数对压缩性能进行优化。
[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
<h2>Welcome to nginx!</h2>
<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>
<h2>this is test web</h2>
<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]#
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。