发现一个nginx LUA开发Web App的框架

nginx是个好东西, nginx的openrtsy发行版本更是个好东西。

今天又发现个好东西 :Moochine

MOOCHINE - 一个简单的轻量级的web framework, 基于ngx_OpenResty(ngx_lua,ttp://openresty.org) 做的框架,

使用例子  https://github.com/appwilldev/moochine-demo



可以让我们构建WebApp 更加的简单,具体使用方法请看具体的 moochine-demo

request对象的属性和方法


--属性
method          = ngx.var.request_method    -- http://wiki.nginx.org/HttpCoreModule#.24request_method
schema          = ngx.var.schema            -- http://wiki.nginx.org/HttpCoreModule#.24scheme
host            = ngx.var.host              -- http://wiki.nginx.org/HttpCoreModule#.24host
hostname        = ngx.var.hostname          -- http://wiki.nginx.org/HttpCoreModule#.24hostname
uri             = ngx.var.request_uri       -- http://wiki.nginx.org/HttpCoreModule#.24request_uri
path            = ngx.var.uri               -- http://wiki.nginx.org/HttpCoreModule#.24uri
filename        = ngx.var.request_filename  -- http://wiki.nginx.org/HttpCoreModule#.24request_filename
query_string    = ngx.var.query_string      -- http://wiki.nginx.org/HttpCoreModule#.24query_string
user_agent      = ngx.var.http_user_agent   -- http://wiki.nginx.org/HttpCoreModule#.24http_HEADER
remote_addr     = ngx.var.remote_addr       -- http://wiki.nginx.org/HttpCoreModule#.24remote_addr
remote_port     = ngx.var.remote_port       -- http://wiki.nginx.org/HttpCoreModule#.24remote_port
remote_user     = ngx.var.remote_user       -- http://wiki.nginx.org/HttpCoreModule#.24remote_user
remote_passwd   = ngx.var.remote_passwd     -- http://wiki.nginx.org/HttpCoreModule#.24remote_passwd
content_type    = ngx.var.content_type      -- http://wiki.nginx.org/HttpCoreModule#.24content_type
content_length  = ngx.var.content_length    -- http://wiki.nginx.org/HttpCoreModule#.24content_length

headers         = ngx.req.get_headers()     -- http://wiki.nginx.org/HttpLuaModule#ngx.req.get_headers
uri_args        = ngx.req.get_uri_args()    -- http://wiki.nginx.org/HttpLuaModule#ngx.req.get_uri_args
post_args       = ngx.req.get_post_args()   -- http://wiki.nginx.org/HttpLuaModule#ngx.req.get_post_args
socket          = ngx.req.socket            -- http://wiki.nginx.org/HttpLuaModule#ngx.req.socket

--方法
request:read_body()                         -- http://wiki.nginx.org/HttpLuaModule#ngx.req.read_body
request:get_uri_arg(name, default)
request:get_post_arg(name, default)
request:get_arg(name, default)

request:get_cookie(key, decrypt)
request:rewrite(uri, jump)                  -- http://wiki.nginx.org/HttpLuaModule#ngx.req.set_uri
request:set_uri_args(args)                  -- http://wiki.nginx.org/HttpLuaModule#ngx.req.set_uri_args

response对象的属性和方法

--属性
headers         = ngx.header                -- http://wiki.nginx.org/HttpLuaModule#ngx.header.HEADER

--方法
response:set_cookie(key, value, encrypt, duration, path)
response:write(content)
response:writeln(content)
response:ltp(template,data)
response:redirect(url, status)              -- http://wiki.nginx.org/HttpLuaModule#ngx.redirect

response:finish()                           -- http://wiki.nginx.org/HttpLuaModule#ngx.eof
response:is_finished()
response:defer(func, ...)                   -- 在response返回后执行

支持 Multi-App 与 Sub-App

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
非常好的话题!NginxLua的结合是一个强大的开发组合,它允许您通过编写Lua脚本来扩展和定制Nginx的功能。您可以在Nginx配置文件中使用Lua指令,并在Lua脚本中访问和操作请求和响应对象。 下面是一些关于Nginx Lua开发的常见问题: 1. 如何启用Nginx Lua模块? 要启用Nginx Lua模块,您需要在编译Nginx时添加--with-http_lua_module选项。然后,您可以在Nginx配置文件中使用lua指令。 2. 如何编写Lua脚本并在Nginx中使用? 您可以在Nginx配置文件中使用lua指令来包含和执行Lua脚本。例如,您可以使用lua_block指令将Lua代码块嵌入到配置文件中,或者使用lua_file指令引用外部的Lua脚本文件。 3. Lua脚本可以用于哪些方面的开发? 使用Lua脚本,您可以在Nginx中执行各种任务,如路由请求、验证和处理请求、修改请求头、访问数据库等。您可以通过编写Lua函数来实现这些功能,并在配置文件中调用它们。 4. 是否有一些常用的Nginx Lua开发库或框架? 是的,有一些常用的Nginx Lua开发库或框架,例如OpenResty和Lapis。OpenResty是一个基于NginxLua的全功能Web应用服务器,提供了许多有用的Lua库和模块。Lapis是一个基于OpenResty的Web框架,简化了使用Lua进行Web开发的过程。 5. 是否有一些示例或教程来学习Nginx Lua开发? 是的,有很多在线资源可以帮助您学习Nginx Lua开发。您可以查阅官方文档、教程和示例代码,也可以参考一些社区分享的博客文章和论坛讨论。 希望这些回答能对您有所帮助!如果您有更多关于Nginx Lua开发的问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

langeldep

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值