i want use lua-resty-checkups to realize a micro service gateway,this is my way:
set upstream variable on set_by_lua
set proxy_pass with upstream variable
but, i find this way does not work, it throw a error : no resolver defined to resolve test_upstream,how can i resolve it? Did I do it the wrong way? this is my code:
nginx.conf
lua_shared_dict state 10m;
lua_shared_dict mutex 1m;
lua_shared_dict locks 1m;
lua_shared_dict config 10m;
upstream charles{
server 10.72.8.81:80 weight=2;
}
init_by_lua_block {
local config = require "config"
local checkups = require "resty.checkups.api"
checkups.init(config)
}
init_worker_by_lua_block {
local config = require "config"
local checkups = require "resty.checkups.api"
checkups.prepare_checker(config)
checkups.create_checker()
}
server {
location / {
set $dynamic_proxy '';
set_by_lua_file $test_var /opt/openresty/lua_script/dynamic_route.lua;
proxy_pass http://$dynamic_proxy/;
}
dynamic_route.lua
local ngx_re = require "ngx.re"
local uri = ngx.var.uri
local array = ngx_re.split(uri, "/")
local context_path = array[2]
if "charles" == context_path then
ngx.var.dynamic_proxy = "charles"
end
if "charles1" == context_path then
ngx.var.dynamic_proxy = "test_upstream"
end
<!DOCTYPE html>
<html>
<head>
<title>Welcome to OpenResty!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to OpenResty!</h1>
<p>If you see this page, the OpenResty web platform is successfully installed and
working. Further configuration is required.</p>
For online documentation and support please refer to
openresty.org.
Commercial support is available at
openresty.com.
i want use lua-resty-checkups to realize a micro service gateway,this is my way:
nginx.conf
dynamic_route.lua
config.lua
request test
http://localhost/charles
For online documentation and support please refer to openresty.org.
Commercial support is available at openresty.com.
Thank you for flying OpenResty.