游戏人生
首页
(current)
GameDevTools
登陆
|
注册
个人中心
注销
OpenResty 教程
OpenResty 简介
OpenResty Ubuntu安装
OpenResty 第一个例子
OpenResty 目录结构
OpenResty 启动和关闭
OpenResty 热重启
OpenResty 执行lua代码
OpenResty 执行lua文件
OpenResty 网站服务
OpenResty 访问指定网页
OpenResty 多网页网站
OpenResty 日志
OpenResty 流水线
OpenResty ip黑名单
OpenResty 反向代理
OpenResty 负载均衡
<< OpenResty 执行lua代码
OpenResty 网站服务 >>
OpenResty 执行lua文件
上一篇了解到在 nginx.conf 配置文件中,可以执行lua代码。 但是在配置文件中写代码,总感觉怪怪的,不符合用户习惯。 所以来看下 OpenResty 如何执行lua 文件。 ------------ #### 1. 新建lua 脚本文件 进入到work目录 创建目录,存放lua脚本 ```shell cd ~/work mkdir -p service/http ```  创建lua脚本文件 ```shell nano service/http/test.lua ``` 将下面的lua代码粘贴到lua脚本里。 ```shell local iTimeStamp=os.time() ngx.say("welcome to www.thisisgame.com.cn,now is " .. iTimeStamp .. ",powerd by OpenResty with luafile") ```  > ctrl+o 保存 ctrl_x 退出 ------------ #### 2. 修改nginx.conf 配置文件 删除 `content_by_lua_block` 标签。 将其替换为 `content_by_lua_file` 标签,并指定lua脚本文件路径。 ```shell worker_processes 1; error_log logs/error.log; events { worker_connections 1024; } http { server { listen 8080; location / { default_type text/html; content_by_lua_file service/http/test.lua; } } } ``` ------------ #### 3.重启/启动 OpenResty 服务 重启 OpenResty: ```shell nginx -p `pwd`/ -s reload ```  可以看到 新的配置文件生效了,lua脚本被执行了。
<< OpenResty 执行lua代码
OpenResty 网站服务 >>
提交
5ec8e768f9046103c7132d0b