前面提到过,nginx在项目中的作用。其实还有很多高级模块功能,例如今天我们利用OpenResty来防止一些IP恶意攻击。
OpenResty® 是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库、第三方模块以及大多数的依赖项。用于方便地搭建能够处理超高并发、扩展性极高的动态 Web 应用、Web 服务和动态网关。
官方地址:http://openresty.org/cn/
环境搭建
本文使用centos 7进行操作,安装nginx,本处安装nginx并非是openresty前提,只是为了演示openresty安装后,访问地址会将nginx变成openresty
wget下载
解压并执行安装命令
访问地址

安装openresty,先下载openresty,
(此版本最终一直无法加载一些lua脚本,最终使用openresty-1.15.8.3版本成功)

解压&安装
执行完后,我们启动openresty中得nginx,注意,切换到openresty安装得路径
启动后,访问,发现nginx变成了openresty

配置nginx.conf
测试lua功能


可以看到已经可以使用lua脚本,下面我们将redis sdk引用进来

配置请求路径访问lua脚本(本处只是做一个demo,如果对所有路径进行访问限制,可以拦截/,然后lua验证通过后,进行请求转发)

lua脚本
启动nginx后,请求一直报错

这个问题困扰了我很久(凡是不要一上来就最新版本,吐血说明)
windows版本的openresty并没有出现此问题,liunux一直都有问题,最终降低了openresty版本,实验成功,openresty-1.15.8.3版本
正常请求

异常请求

最后openresty的运行周期图如下,可以从整体上了解openresty
原文地址:https://www.toutiao.com/i6901200619571364356/
本文链接:https://my.lmcjl.com/post/19294.html
4 评论