编写Lua脚本
路径在/lua/hello.lua
编写 hello.lua 内容:
ngx.say("hello, world")
[root@zjj101 lua]# pwd
/lua
[root@zjj101 lua]# cat hello.lua
ngx.say("hello, world")
[root@zjj101 lua]#
配置OpenResty的nginx.conf配置文件
nginx.conf文件修改内容
http模块儿里面添加server模块儿
server {
listen 8081;
location / {
content_by_lua_file '/lua/hello.lua';
}
}
刷新配置文件
需要配置环境变量,如果不会的话,查看
https://www.yuque.com/docs/share/68e00d5d-4a3f-4c1a-8ee0-a32ac8114190?# 《OpenResty配置环境变量》
刷新配置文件命令:
root@zjj101 lua]# openresty -s reload
执行查看结果
[root@zjj101 lua]# curl -i 127.0.0.1:8081
HTTP/1.1 200 OK
Server: openresty/1.15.8.1
Date: Fri, 11 Jun 2021 10:05:11 GMT
Content-Type: application/octet-stream
Transfer-Encoding: chunked
Connection: keep-alive
hello, world
[root@zjj101 lua]#
总结
后面 Lua 代码的变更,你就可以直接修改 hello.lua 这个文件,而不是 nginx.conf 了。