Nginx+lua环境搭建
2024-08-28 03:03:35
其实有点类似WampServer一站式安装包
wget http://openresty.org/download/ngx_openresty-1.7.10.1.tar.gz tar -zxvf ngx_openresty-1.7.10.1.tar.gz cd ngx_openresty-1.7.10.1 ./configure make && make install
configure之前需要安装的相关组件
yum -y install pcre-devel yum -y install gcc zlib zlib-devel openssl openssl-devel
安装目录默认会在
cd /usr/local/openresty/
测试lua环境是否正常
lua print("hello")
测试nginx+lua
cd /usr/local/openresty/nginx/conf
在nginx.conf里添加测试内容
location /hello { default_type 'text/plain'; content_by_lua 'ngx.say("ok")'; }
location /say {
default_type text/html;
content_by_lua '
ngx.say("<p>hello, world</p>")
ngx.say(tostring(ngx.var.remote_addr),"<br/>")
ngx.say(tostring(ngx.var.arg_name),"<br/>")
';
}
启动nginx
sbin/nginx
测试:
[root@k2 nginx]# curl 'http://localhost/hello' ok
浏览器访问:
测试3:
location ~ /lua_request/(\d+)/(\d+) { #设置nginx变量 ; set $b $host; default_type "text/html"; #nginx内容处理 content_by_lua_file /test/test_request.lua; #内容体处理完成后调用 echo_after_body "ngx.var.b $b"; }
test_request.lua
--nginx变量 local var = ngx.var ngx.say("ngx.var.a : ", var.a, "<br/>") ngx.say("ngx.var.b : ", var.b, "<br/>") ngx.say(], "<br/>") ngx.; ngx.say("<br/>") --请求头 local headers = ngx.req.get_headers() ngx.say("headers begin", "<br/>") ngx.say("Host : ", headers["Host"], "<br/>") ngx.say("user-agent : ", headers["user-agent"], "<br/>") ngx.say("user-agent : ", headers.user_agent, "<br/>") for k,v in pairs(headers) do if type(v) == "table" then ngx.say(k, " : ", table.concat(v, ","), "<br/>") else ngx.say(k, " : ", v, "<br/>") end end ngx.say("headers end", "<br/>") ngx.say("<br/>") --get请求uri参数 ngx.say("uri args begin", "<br/>") local uri_args = ngx.req.get_uri_args() for k, v in pairs(uri_args) do if type(v) == "table" then ngx.say(k, " : ", table.concat(v, ", "), "<br/>") else ngx.say(k, ": ", v, "<br/>") end end ngx.say("uri args end", "<br/>") ngx.say("<br/>") --post请求参数 ngx.req.read_body() ngx.say("post args begin", "<br/>") local post_args = ngx.req.get_post_args() for k, v in pairs(post_args) do if type(v) == "table" then ngx.say(k, " : ", table.concat(v, ", "), "<br/>") else ngx.say(k, ": ", v, "<br/>") end end ngx.say("post args end", "<br/>") ngx.say("<br/>") --请求的http协议版本 ngx.say("ngx.req.http_version : ", ngx.req.http_version(), "<br/>") --请求方法 ngx.say("ngx.req.get_method : ", ngx.req.get_method(), "<br/>") --原始的请求头内容 ngx.say("ngx.req.raw_header : ", ngx.req.raw_header(), "<br/>") --请求的body内容体 ngx.say("ngx.req.get_body_data() : ", ngx.req.get_body_data(), "<br/>") ngx.say("<br/>")
脚本测试
wget --post-data 'a=1&b=2' 'http://127.0.0.1/lua_request/1/2?a=3&b=4' -O -
访问:
http://192.168.1.120/lua_request/1/2?a=3&b=4
参考:
http://openresty.org/
https://m.oschina.net/blog/344540
http://jinnianshilongnian.iteye.com/blog/2186448
最新文章
- 基于TCP的网络编程
- hdu 1503, LCS variants, find a LCS, not just the length, backtrack to find LCS, no extra markup 分类: hdoj 2015-07-18 16:24 139人阅读 评论(0) 收藏
- 【LeetCode OJ】Construct Binary Tree from Preorder and Inorder Traversal
- 性能测试工具 转自https://yq.aliyun.com/articles/35149?spm=5176.100239.blogcont35147.8.rsow6k
- 背水一战 Windows 10 (1) - C# 6.0 新特性
- 转载 linux内核 asmlinkage宏
- [CareerCup] 8.8 Othello Game 黑白棋游戏
- Android+OpenCV 摄像头实时识别模板图像并跟踪
- 关于T-SQL重编译那点事,WITH RECOMPILE和OPTION(RECOMPILE)区别仅仅是存储过程级重编译和SQL语句级重编译吗
- css 兼容 position:fixed
- Chatwin商务通
- javascript 中 ";!function(){}() "; 是什么意思?
- iOS 圆角那些事(转)
- 创建简单的Python列表
- UnicodeEncodeError: &#39;gbk&#39; codec can&#39;t encode character &#39;\xa0&#39; in position 1987: illegal multibyte sequence
- Java新知识系列 四
- excel 删除重复项
- Elasticsearch 性能监控基础【转】
- Python教程:进击机器学习(五)--Scipy《转》
- winhex十六进制常用快捷键
热门文章
- PHP获取IP地址
- rest api设计的一般原则
- ZJOIDay2T1 BB题解
- 插入备份数据 报 IDENTITY_INSERT 为 ON 时解决方法
- iOS开源App整理
- IDEA Error:java: 未结束的字符串文字
- javax.imageio.IIOException: Can&#39;t create cache file!
- centos7精简版(minimal)killall: command not found
- Qt字符转换
- ABAP 内表的行列转换-NEW