想要整合,必須先要明確自己的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
恭喜你配置成功。