update
Browse files- app copy.lua +18 -1
- nginx.conf +4 -1
app copy.lua
CHANGED
|
@@ -14,7 +14,7 @@ if uri == '/' then -- uri为 / ,退出运行
|
|
| 14 |
ngx.exit(ngx.HTTP_OK)
|
| 15 |
end
|
| 16 |
|
| 17 |
-
local api_version, api_pxoxy_pass_url_indicator = uri:match("/([^/]+)/(.*)")
|
| 18 |
|
| 19 |
ngx.say("api_version: ", api_version)
|
| 20 |
ngx.say("api_pxoxy_pass_url_indicator: ", api_pxoxy_pass_url_indicator)
|
|
@@ -23,7 +23,24 @@ pass_url = pass_url:gsub("http/", "http://")
|
|
| 23 |
pass_url = pass_url:gsub("https/", "https://")
|
| 24 |
ngx.say("pass_url: ", pass_url)
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
|
|
|
|
|
|
| 14 |
ngx.exit(ngx.HTTP_OK)
|
| 15 |
end
|
| 16 |
|
| 17 |
+
local api_version, api_pxoxy_pass_url_indicator = uri:match("/?([^/]+)/?(.*)")
|
| 18 |
|
| 19 |
ngx.say("api_version: ", api_version)
|
| 20 |
ngx.say("api_pxoxy_pass_url_indicator: ", api_pxoxy_pass_url_indicator)
|
|
|
|
| 23 |
pass_url = pass_url:gsub("https/", "https://")
|
| 24 |
ngx.say("pass_url: ", pass_url)
|
| 25 |
|
| 26 |
+
-- 根据版本号加载不同的 Lua 文件
|
| 27 |
+
-- local lua_path = "app_" .. api_version
|
| 28 |
+
-- ngx.say("lua_path: ", lua_path)
|
| 29 |
+
-- require(lua_path)
|
| 30 |
+
local lua_path = "app/" ..api_version .. "/app"
|
| 31 |
+
ngx.say("lua_path: ", lua_path)
|
| 32 |
+
module = require("app/" .. api_version .. "/app") --require 是没问题的
|
| 33 |
|
| 34 |
|
| 35 |
+
-- 检查模块是否加载成功
|
| 36 |
+
if type(module) ~= "table" then
|
| 37 |
+
ngx.say("Error: Failed to load module")
|
| 38 |
+
ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
|
| 39 |
+
end
|
| 40 |
+
|
| 41 |
+
-- 调用模块中的函数
|
| 42 |
+
module.some_function() -- 调用 some_function
|
| 43 |
+
module.another_function() -- 调用 another_function
|
| 44 |
|
| 45 |
|
| 46 |
+
ngx.say("module.a: ", module.a)
|
nginx.conf
CHANGED
|
@@ -16,7 +16,10 @@ http {
|
|
| 16 |
|
| 17 |
location / {
|
| 18 |
default_type text/html;
|
| 19 |
-
content_by_lua_file /data/myapp/app.lua;
|
|
|
|
|
|
|
|
|
|
| 20 |
}
|
| 21 |
}
|
| 22 |
}
|
|
|
|
| 16 |
|
| 17 |
location / {
|
| 18 |
default_type text/html;
|
| 19 |
+
# content_by_lua_file /data/myapp/app.lua;
|
| 20 |
+
rewrite_by_lua_block {
|
| 21 |
+
ngx.say("Hello World!")
|
| 22 |
+
}
|
| 23 |
}
|
| 24 |
}
|
| 25 |
}
|