二、OpenResty的应用编写hello lua和关闭缓存

╄→гoц情女王★ 提交于 2020-02-19 04:40:42

一、编写hello lua

1、停止nginx进程

打开/usr/local/openresty/nginx/conf/nginx.conf

在其中加入

2、执行

nginx -s reload

 该命令用于配置文件被修改后时使用

这时候会报错

nginx: [error] open() "/usr/local/openresty/nginx/logs/nginx.pid" failed (2: No such file or directory)

输入下面代码解决:

/usr/local/openresty/nginx/sbin/nginx -c /usr/local/openresty/nginx/conf/nginx.conf

此时nginx会自动启动,不用再start了

 

该方法是在Nginx的配置文件的嵌入Lua代码

当代码逻辑复杂时就不适合在配置文件中写了,因此可以引用第三方脚本

二、引入lua代码文件编写hello lua

1、在nginx.conf中编写content_by_lua_file

2、创建lua文件夹,编写hello.lua

mkdir lua

vi hello.lua

3、查看结果

curl 127.0.0.1/hello

三、lua_code_cache

在上面的脚本中,修改了内容,则再次访问时还是原来的结果,这是因为其中有缓存,因此我们要将lua_code_cache关闭(注意生产环境不能关闭,因为会影响性能,开发环境可以关闭进行调试)

 再将hello.lua内容修改为hello moon

nginx -s reload

 

内容改为hello sun

证明现在缓存已经关闭,至此修改代码后不用重启nginx了

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!