OpenResty入门
写一个小例子--输出随机字符串
编写nginx配置文件
location /random {
content_by_lua_file /usr/local/openresty/nginx/conf/lua/random.lua;
}
编写random.lua文件
local args = ngx.req.get_uri_args()
local salt = args.salt
if not salt then
ngx.exit(ngx.HTTP_BAD_REQUEST)
end local string = ngx.md5(ngx.time() .. salt)
ngx.say(string)
检查语法
./nginx -t -c /usr/local/openresty/nginx/conf/nginx.conf
重启nginx
./nginx -s reload -c /usr/local/openresty/nginx/conf/nginx.conf
测试一下
curl 127.0.0.1/random?salt=123
成功输出了随机字符串
ea14f7a36e29925f3e9e318128f989f7
ngx lua API--post请求获取并输出userAgent
1. 编写userAgent.lua文件
local json = require "cjson" ngx.req.read_body()
local args = ngx.req.get_post_args() if not args or not args.info then
ngx.exit(ngx_HTTP_BAD_REQUEST)
end local client_ip = ngx.var.remote_addr
local user_agent = ngx.req.get_headers()['user-agent'] or ''
local info = ngx.decode_base64(args.info) local response = {}
response.info = info
response.ip = client_ip
response.user_agent = user_agent ngx.say(json.encode(response))
2. 修改nginx配置文件
location /agent {
content_by_lua_file /usr/local/openresty/nginx/conf/lua/userAgent.lua;
}
3. 检查配置语法并重启nginx
[root@VM_0_10_centos sbin]# ./nginx -t -c /usr/local/openresty/nginx/conf/nginx.conf
nginx: the configuration file /usr/local/openresty/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/openresty/nginx/conf/nginx.conf test is successful
[root@VM_0_10_centos sbin]# ./nginx -s reload -c /usr/local/openresty/nginx/conf/nginx.conf
4. 使用curl进行测试
[root@VM_0_10_centos sbin]# curl -i --data 'info=addgfdgjkljdfgjkl65632dsgds' 127.0.0.1/agent
HTTP/1.1 OK
Server: openresty/1.13.6.1
Date: Sun, Sep :: GMT
Content-Type: application/octet-stream
Transfer-Encoding: chunked
Connection: keep-alive {"info":"i#\b䗮zip":"127.0.0.1","user_agent":"curl\/7.61.0"}
连接数据库--操作MySQL


操作Redis

OpenResty入门的更多相关文章
- openresty入门文章(笔者自用)
推荐好的openresty入门介绍文章:https://www.cnblogs.com/digdeep/p/4859575.html
- openresty入门12 openresty php 整合
利用 openresty 的 drizzle-nginx-module模块 读取数据 传递到 php后端 利用到 openresty 的并发,无阻塞,mysql连接池,memcache|redis ...
- OpenResty入门之使用Lua扩展Nginx
记住一点:nginx配置文件很多坑来源自你的空格少了或多了. 1.Centos下载安装 如果你的系统是 Centos 或 RedHat 可以使用以下命令: yum install readline-d ...
- OpenResty入门之使用Lua开发Nginx插件
记住一点:nginx配置文件很多坑来源自你的空格少了或多了. OpenResty OpenResty 是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库.第 ...
- 《用OpenResty搭建高性能服务端》笔记
概要 <用OpenResty搭建高性能服务端>是OpenResty系列课程中的入门课程,主讲人:温铭老师.课程分为10个章节,侧重于OpenResty的基本概念和主要特点的介绍,包括它的指 ...
- Lua脚本语言快速入门手册
学了两天Lua语言,感叹其短小精悍,上手极快,语法还很舒服,不错!整理下学习过程中经常用到的基础知识,共勉! Lua用法简述 Lua语言是在1993年由巴西一个大学研究小组发明,其设计目标是作为嵌入式 ...
- OpenResty 社区王院生:APISIX 的高性能实践
2019 年 7 月 6 日,OpenResty 社区联合又拍云,举办 OpenResty × Open Talk 全国巡回沙龙·上海站,OpenResty 软件基金会联合创始人王院生在活动上做了&l ...
- OpenResty学习指南(一)
我的博客: https://www.luozhiyun.com/archives/217 想要学好 OpenResty,你必须理解下面 8 个重点: 同步非阻塞的编程模式: 不同阶段的作用: LuaJ ...
- OpenResty搭建高性能服务端
OpenResty搭建高性能服务端 Socket编程 Linux Socket编程领域为了处理大量连接请求场景,需要使用非阻塞I/O和复用,select.poll.epoll是Linux API提 ...
随机推荐
- androidStudio修改包名 Android 如何修改包名(同一个手机可以跑2个eros 项目)。
修改applicationId(gradle.properties). 2.即时同步更新过去,否则不报错
- Consider everything deeply but still remain fearless.
Consider everything deeply but still remain fearless.愿你能深思熟虑,但始终无所畏惧.
- HTTPS与SSL(一)
1. HTTPS HTTPS(全称:Hypertext Transfer Protocol over Secure Socket Layer),是以安全为目标的HTTP通道,简单讲是HTTP的安全版 ...
- Eclipse升级到ADT-23.0.2 Fail 解决方法
工具:eclipse3.7.2 升级ADT:从ADT-22.3.0到ADT-23.0.2 错误信息: Cannot complete the install because of a conflict ...
- 【extjs6学习笔记】1.12 初始: Working with DOM
http://www.extjs-tutorial.com/extjs/working-with-dom Ext JS是一个DHTML库. 它通过使用JavaScript创建或操作DOM元素来创建UI ...
- Team Foundation 版本控制
与 Visual Studio 的一流集成. 使用富文件和文件夹差异工具突出显示代码更改. 借助强大的可视化跨分支跟踪代码更改. 集成的代码评审工具有助于在签入代码之前获得反馈. 使用托管版本或本地版 ...
- 美国L1签证面谈的时候一般VO会问到什么问题?
L签证:L签证签发给被其中国公司调派到美国分公司或合资公司工作的人员.申请人必须将在美国担任经理级职务或具有专业知识,且在申请签证前的三年中至少为同一雇主或公司连续工作至少一年.签证签发费将因签证的入 ...
- HTML、CSS、JS、JQ速查笔记
一.HTML 1.编写html文件 a.格式 <!DOCTYPE html> <html> <head> <title>标题</title& ...
- 微软高性能缓存AppFabric (一) 安装
博客原文链接:http://www.cnblogs.com/Qbit/p/6088703.html AppFabric 缓存功能的前身是VeloCity ,它是基于windows平台的一个高速内存缓存 ...
- HDU3874 线段树 + 离线处理
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3874 , 线段树(或树状数组) + 离线处理 下午做了第一道离线处理的题目(HDU4417),多少有点 ...