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. 浏览器DOM操作

    HTML Node 节点 常用API 高效遍历 DOM Repaint and reflow 插入大量内容避免重绘和回流 style 样式操作 DOM事件 HTML - innerHTML:内部HTM ...

  2. jQuery 中$.ajax()方法参数详解

    $.ajax({ url:'test.do', data:{id:,name:'xiaoming'}, type:'post', dataType:'json', success:function(d ...

  3. Ubuntu下配置Nginx+PHP

    1.安装Nginxapt-get install nginx 2.启动Nginxservice nginx start 3.访问服务器IP 如果看到“Welcome to nginx!”说明安装好了. ...

  4. 二十四 Python分布式爬虫打造搜索引擎Scrapy精讲—爬虫和反爬的对抗过程以及策略—scrapy架构源码分析图

    1.基本概念 2.反爬虫的目的 3.爬虫和反爬的对抗过程以及策略 scrapy架构源码分析图

  5. magento: Your web server is configured incorrectly. As a result, configuration files with sensitive information are accessible from the outside 解决方案

    在linux(以UBUNTU, CENTOS为例)下安装完成magento时,在进入后台时, 有些童鞋可能会发现有如下的提示: Your web server is configured incorr ...

  6. C++:栈(stack)的模板类实现

    1.基本概念 栈中的元素遵守“先进后出”的原则(LIFO,Last In First Out) 只能在栈顶进行插入和删除操作 压栈(或推入.进栈)即push,将数据放入栈顶并将栈顶指针加一 出栈(或弹 ...

  7. CSS技巧和经验

    如何清除图片下方出现几像素的空白间隙 方法1 img { display: block; } 方法2 除了top值,还可以设置为text-top | middle | bottom | text-bo ...

  8. 【2018 “百度之星”程序设计大赛 - 初赛(B)- 1001】degree

    Problem Description 度度熊最近似乎在研究图论.给定一个有 N 个点 (vertex) 以及 M 条边 (edge) 的无向简单图 (undirected simple graph) ...

  9. dell c6220II lsi阵列卡

    1.如果在lsi阵列卡上有多个raid,那么需要在第一个创建的raid上装系统,或者说先创建装系统的raid,否则可能报 hard disk error(centos 6.6) 2.热插拔的后果:如果 ...

  10. java中a++和++a的区别详解

    java中的++操作无论在前还是在后,都是在变量自身的值加1,接下来将具体描述两者的区别 int a =5; int b =a++; System.out.println(b); 1.通俗易懂的理解是 ...