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提 ...
随机推荐
- 极飞P20农业无人机多机协同作业飞行
来自为知笔记(Wiz)
- a标签常用跳转
1.a标签跳转qq <a href="http://wpa.qq.com/msgrd?v=3&uin=123456789&site=qq&menu=yes&qu ...
- Mysql数据库操作语句总结(二)
Mysql字符串字段判断是否包含字符串的3中方法 方法一: select * from user where email like "%b@email.com%";// 这个理解起 ...
- Hibernate数据库的操作
参考网址: https://www.cnblogs.com/jack1995/p/6952704.html 1.最简单的查询 List<Special> specials = (List& ...
- 《Unity預計算即時GI》笔记:三、Clusters和总结
Clusters 叢集,透過修改叢集(Clusters)也是一個降低Unity預計算流程所需要執行的工作數量的好方法.降低叢集數量也能提高執行時的效能. 當採用PRGI來計算場景光照時,Unity會簡 ...
- C#高性能Socket服务器IOCP实现
引言我一直在探寻一个高性能的Socket客户端代码.以前,我使用Socket类写了一些基于传统异步编程模型的代码(BeginSend.BeginReceive,等等)也看过很多博客的知识,在linux ...
- tomcat jvm参数优化
根据gc(垃圾回收器)的选择,进行参数优化 JVM给了三种选择:串行收集器.并行收集器.并发收集器,但是串行收集器只适用于小数据量的情况,所以这里的选择主要针对并行收集器和并发收集器. -XX:+Us ...
- LeetCode Find Peak Element 找临时最大值
Status: AcceptedRuntime: 9 ms 题意:给一个数组,用Vector容器装的,要求找到一个临时最高点,可以假设有num[-1]和num[n]两个元素,都是无穷小,那么当只有一个 ...
- 工作中碰到的css问题解决方法
好久都没来这写东西了,都长草了.刚解决的两个小问题,先记下来 textarea横向没有滚动条加上 wrap="off"这个属性 英文单词不断行加上这个 word-break:bre ...
- yii:高级应用程序搭建数据库的详细流程
上一章已经把高级应用程序的环境搭配成功,那么下一步就是搭建数据库了. 首先,我们先去创建一个数据库,比如:demo 创建完之后,我们重要的就是将文件中的数据进行一个更新,在www/advancend/ ...