想要整合,必须先要明确自己的Nginx安装目录,nginx在openresty中体现代理的作用。我安装目录是
/usr/local/Cellar/openresty/1.13.6.1/nginx
1.首先我们修改Nginx下的conf下的nginx.conf文件
http {
default_type application/octet-stream;
lua_package_path "/usr/example/lualib/?.lua;;"; #lua 模块
lua_package_cpath "/usr/example/lualib/?.so;;"; #c模块
include /usr/example/example.conf;
}
lualib文件夹是安装openresty自带的,example.conf是我们自己建的文件,nginx这是转发去加载example.conf文件。
2.编写example文件的内容
server {
listen 80;
server_name _;
location /lua {
default_type 'text/html';
lua_code_cache off;
content_by_lua_file /usr/example/lua/test.lua;
}
}
可以看到此时启动的是默认80端口,具体执行文件为
/usr/example/lua/test.lua
那我们下面的内容是编写test.lua
3.编写test.lua
ngx.say("hello world");
这里就简单的输出一句话。
所有东西配置好了,这是使我们丰收的时刻了。
下面访问localhost/lua 如果输出helloworld
恭喜你配置成功。