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. .Net Core 修改默认的启动端口

    今天无意中发现一个变化,因为很久没看.net core的项目了,发现项目启动的默认端口已经不是5000了,记得很清楚,最早那还是.net core 1.x版本的时候,每次启动都会默认是5000端口号, ...

  2. Lua学习笔记1,基本数据类型

    1.字符串的连接使用的是  .. ,如 print(123 .. 44) 输出 12344 print ('a' .. 'b') 输出 ab print(123 .. 44)这句的时候 .. 两边要空 ...

  3. 玲珑oj 1121 思维

    1121 - Reverse the lights Time Limit:2s Memory Limit:256MByte Submissions:376Solved:111 DESCRIPTION ...

  4. Hibernate所用15个jar包

    Hbernate3.jar-------------------核心包antlr.jar----------------------------语言转换工具,hibernate用他将hql语句转换为s ...

  5. web前端 —— 移动端知识的一些总结

    个人在移动端的一些总结归纳,有新的知识点会一直更新 一.css部分 1.meta标签 <meta name="viewport" content="width=de ...

  6. Linux下记录所有用户的登录和操作日志

    Linux下记录所有用户的登录和操作日志   一般我们可以用history命令来查看用户的操作记录,但是这个命令不能记录是哪个用户登录操作的,也不能记录详细的操作时间,且不完整:所以误操作而造成重要的 ...

  7. QUnit 学习笔记 使用说明(一)

    一.单元测试前言 什么是单元测试? 如果是新接触单元测试的童鞋,简要的解释:就是一个JS函数/功能/模块的测试. 单元测试的工具:这里介绍QUnit Qunit原本是jqury家的,不过现在已经独立了 ...

  8. igmpproxy源代码学习——配置信息加载 loadConfig

            在igmpproxy主程序运行之前需要先读取配置文件,igmpproxy的配置文件通常为/etc/igmpproxy.conf或者/var/igmpproxy.conf 其内容如下: ...

  9. 记一次GreenPlum性能调优

    在部署了的GreenPlum集群中进行数据查询时,发现数据量一旦大了,查询一跑就中断,提示某个segment中断了连接. ERROR 58M01 "Error on receive from ...

  10. phpMyAdmin 尝试连接到 MySQL 服务器,但服务器拒绝连接

    phpMyAdmin 尝试连接到 MySQL 服务器,但服务器拒绝连接--解决方法     phpMyAdmin 尝试连接到 MySQL 服务器,但服务器拒绝连接.您应该检查配置文件中的主机.用户名和 ...