安装openresty(升级化的nginx,里面含有更多的第三方模块)

解压编译安装

[[email protected] ~]# tar zxf openresty-1.13.6.1.tar.gz 

[[email protected] ~]# cd openresty-1.13.6.1

[[email protected]]#./configure --prefix=/usr/local/lnmp/openresty

编译第一部完成后,gmake  && gmake install

开启之前需要关闭掉原来的nginx,否则端口会冲突

安装好openresty后,编辑里面的nginx的配置文件,nginx.conf
nginx+memcache与网页重定向

[[email protected] conf]# vim nginx.conf   编辑配置文件

nginx+memcache与网页重定向

nginx+memcache与网页重定向

nginx+memcache与网页重定向

编辑完成之后,保存退出,在openresty中的nginx/sbin目录下启动nginx

[[email protected] openresty-1.13.6.1]# /etc/init.d/memcached start      #开启memcache

此时Php和nginx同时都加了memcache,所以访问的速度会更快

物理机测试:

[[email protected] lnmp]# ab -c 10 -n 1000 http://172.25.18.1/index.php

nginx没有加memcache的时候测试:每秒解决409个请求,错误91

nginx+memcache与网页重定向

加了memcache后访问:每秒解决2864个,0错误

nginx+memcache与网页重定向

[[email protected] lnmp]# ab -c 10 -n 1000 http://172.25.18.1/example.php

Nginx未加memcache :每秒解决2084个

nginx+memcache与网页重定向

加上memcache :每秒解决2847个
nginx+memcache与网页重定向


网页重定向,编辑nginx的配置文件(关闭掉openresty,重新打开原本的nginx)

123行内容:将网页内容定向到https上面,永久定向,注释掉下面内容

nginx+memcache与网页重定向nginx+memcache与网页重定向

真机测试,访问www.westos.org会定向到https://www.westos.org

nginx+memcache与网页重定向

给真机写入解析,可以在网页上看到效果

nginx+memcache与网页重定向

把以bbs结尾的网页定义到bbs.westos.org

nginx+memcache与网页重定向

访问

nginx+memcache与网页重定向

定义以bbs结尾后面还跟网页,则转到bbs.westos.org/index.html

nginx+memcache与网页重定向

测试

nginx+memcache与网页重定向

如果访问bbs.westos.org,则重定向到https://www.westos.org/bbs

nginx+memcache与网页重定向

测试

nginx+memcache与网页重定向

访问以下页面的时候,需要在www.westos.org 定义的目录下(/www1)写index.html

nginx+memcache与网页重定向

为了防止恶意域名解析,通过ip非法访问,将其重定向到合法的域名(www.westos.org)

nginx+memcache与网页重定向

真机测试:

nginx+memcache与网页重定向

图片缓存的过期时间设置

所有以png,jpg,gif结尾的文件缓存时间为30天

nginx+memcache与网页重定向

真机测试:7.2缓存。8.2日过期

nginx+memcache与网页重定向

设置访问的黑名单或者白名单

读取有先后顺序,允许18.0所有网段,然后拒绝所有

nginx+memcache与网页重定向

不允许250访问图片类文件如下:

nginx+memcache与网页重定向

测试:可以访问正常域名:

nginx+memcache与网页重定向

不能访问图片:403拒绝

nginx+memcache与网页重定向

防盗链:

新开启虚拟机server2,安装nginx

Rpm安装后,nginx文件分散在系统各个目录中,在html下写test.html指向server1的图片进行盗取

nginx+memcache与网页重定向

真机写server2的解析

nginx+memcache与网页重定向

然后访问daolian.westos.org/test.html就可以找到srever1中www.westos.org/redhat.jpg的图片文件

为了防止像server2这样的盗链,需要在server1的文件中如下配置,修改nginx.conf

nginx+memcache与网页重定向

此时返回的为403错误,即图片法无打开

做如下修改,指向警告的网页(更加人性化)

nginx+memcache与网页重定向

nginx+memcache与网页重定向

在/www2下放入盗链警告的图片

nginx+memcache与网页重定向

此时再访问,则只能访问到盗链的图片

nginx+memcache与网页重定向



相关文章: