1. 安装
  1. luarocks install lua-resty-template
2. 使用
  配置模板页面位置
    有多种方式:
  a.  直接使用root 目录
    代码如下:    
  1. location /{
  2. root html;
  3. content_by_lua '
  4. local template = require "resty.template"
  5. template.render("view.html",{ message ="Hello, World!"})
  6. ';
  7. }
  view.html 
  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4. <h1>{{message}}</h1>
  5. </body>
  6. </html>
b.  set $template_root
 代码如下:
  1. http {
  2. server {
  3. set $template_root /usr/local/openresty/nginx/html/templates;
  4. location /{
  5. root html;
  6. content_by_lua '
  7. local template = require "resty.template"
  8. template.render("view.html",{ message ="Hello, World!"})
  9. ';
  10. }
  11. }
  12. }
c.  set  template_location(原理:ngx.location.capture from /templates)
代码如下:
  1. http {
  2. server {
  3. set $template_location /templates;
  4. location /{
  5. root html;
  6. content_by_lua '
  7. local template = require "resty.template"
  8. template.render("view.html",{ message ="Hello, World!"})
  9. ';
  10. }
  11. location /templates {
  12. internal;
  13. alias html/templates/;
  14. }
  15. }
 
  3. 参考文档

  1. https://github.com/bungle/lua-resty-template
 
 
 

lua resty template && openresty 使用的更多相关文章

  1. LUA+resty 搭建验证码服务器

    使用Lua和OpenResty搭建验证码服务器 雨客 2016-04-08 16:38:11 浏览2525 评论0 云数据库Redis版 摘要: Lua下有个Lua-GD图形库,通过简单的Lua语句就 ...

  2. openresty + lua 1、openresty 连接 mysql,实现 crud

    最近开发一个项目,公司使用的是 openresty + lua,所以就研究了 openresty + lua.介绍的话,我就不多说了,网上太多了. 写这个博客主要是记录一下,在学习的过程中遇到的一些坑 ...

  3. openresty + lua 4、openresty kafka

    kafka 官网: https://kafka.apache.org/quickstart zookeeper 官网:https://zookeeper.apache.org/ kafka 运行需要 ...

  4. openresty + lua 2、openresty 连接 redis,实现 crud

    redis 的话,openresty 已经集成,ng 的话,自己引入即可. github 地址:https://github.com/openresty/lua-resty-redis github  ...

  5. openresty + lua 3、openresty http 调用

    http 的话,openresty 已经集成,ng 的话,自己引入即可. github 地址:https://github.com/pintsized/lua-resty-http github 里提 ...

  6. 用Nginx+Lua(OpenResty)开发高性能Web应用

    在互联网公司,Nginx可以说是标配组件,但是主要场景还是负载均衡.反向代理.代理缓存.限流等场景:而把Nginx作为一个Web容器使用的还不是那么广泛.Nginx的高性能是大家公认的,而Nginx开 ...

  7. Nginx+Lua(OpenResty)开发高性能Web应用

    使用Nginx+Lua(OpenResty)开发高性能Web应用 博客分类: 跟我学Nginx+Lua开发 架构 ngx_luaopenresty 在互联网公司,Nginx可以说是标配组件,但是主要场 ...

  8. 使用Nginx+Lua(OpenResty)开发高性能Web应用

    摘自(http://jinnianshilongnian.iteye.com/blog/2280928) 在互联网公司,Nginx可以说是标配组件,但是主要场景还是负载均衡.反向代理.代理缓存.限流等 ...

  9. openresty router && template 试用

      router 是一个比较方便的 openresty 路由组件,我们可以用来编写灵活强大的 web 应用,类似的 lua-resty-route 也是很不错的,但是如果是比较简单的直接可以使用 lu ...

随机推荐

  1. spring mvc:练习 @RequestParam(参数绑定到控制器)和@PathVariable(参数绑定到url模板变量)

    spring mvc:练习 @RequestParam和@PathVariable @RequestParam: 注解将请求参数绑定到你的控制器方法参数 @PathVariable: 注释将一个方法参 ...

  2. Vue实例的生命周期created和mounted的区别

    生命周期先上图 什么是生命周期 Vue实例有一个完整的生命周期,也就是从开始创建.初始化数据.编译模板.挂载Dom.渲染→更新→渲染.卸载等一系列过程,我们称这是Vue的生命周期.通俗说就是Vue实例 ...

  3. rsa加解密密钥生成命令

    (1)生成原始RSA私钥文件 rsa_private_key.pem(原始私钥) openssl genrsa -out rsa_private_key.pem 2048 (2)将原始RSA私钥转换为 ...

  4. Linux 系统启动过程,Linux 系统目录结构

    一.Linux 系统启动过程 linux启动时我们会看到许多启动信息. Linux系统的启动过程并不是大家想象中的那么复杂,其过程可以分为5个阶段: 内核的引导. 运行 init. 系统初始化. 建立 ...

  5. Windows 下 左Ctrl和Caps交换

    将以下文本存为后缀为.reg文件,运行并重启即可 左Ctrl和Caps交换 Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTE ...

  6. Qt出现QObject::connect: Cannot queue arguments of type '******'的解决方法

    一般出现这种情况都是自定义的类型进行型号槽连接的时候出现的,使用 假设自定义的类型是MyClass 使用qRegisterMetaType<MyClass>("MyClass&q ...

  7. mac下初始化eclipse的安卓开发ndk开发环境

    最近电脑由windows换成mac了,很多环境都要重新搭建,顺便纪录下,方便以后查阅. 1.先到eclipse官网下载最新版eclipse,我下载的是neon版,下载后直接解压到即可使用(前提是你安装 ...

  8. mac下解决mysql乱码问题

    问题描述:在window平台下面数据库插入.已经查找都是很正常的,但是到mac下面查找.插入就不正常了,之后感觉是mysql的问题然后网上搜索学习了下,果然是mysql的问题.解决方案:首先你要先去看 ...

  9. 使用CGLib完成代理模式遇到的错误

    错误堆栈信息: Exception in thread "main" java.lang.NoClassDefFoundError: org/objectweb/asm/Type ...

  10. window环境下创建Flask项目需要安装常见模块命令

    安装Flask环境 pip install flask==0.10.1 使用命令行操作 pip install flask-script 创建表单 pip install flask-wtf 操作数据 ...