upyun / slardar

Updating your upstream list and run lua scripts without reloading Nginx.
493 stars 111 forks source link

set_by_lua #8

Open wangwj opened 7 years ago

wangwj commented 7 years ago

location / { 好像不支持 set_by_lua指令,想用这个指令实现如下效果 set_by_lua $cur_ups '
url中取一个固定参数的值 '
proxy_pass $scheme://$cur_ups;
} 这样我就可以通过参数的不一样,动态的跳转到对应的upstream

yejingx commented 7 years ago

可以支持 set_by_lua 的。

wangwj commented 7 years ago

@yejingx 是我用的方式不对吗,下面是配置,执行ngins -s reload 后直接报错 server { listen 8080 default_server; access_log logs/access.log main;

set $x_error_code "-";

proxy_next_upstream_tries 2;
proxy_next_upstream_timeout 5s;
proxy_next_upstream error timeout http_502;

proxy_read_timeout 60s;

rewrite_by_lua_file app/src/rewrite.lua;

location / {
    set_by_lua_block $abc {
            return aaa;
    };
    proxy_pass  http://backend;

    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

}

执行命令 /usr/local/slardar/nginx/sbin/nginx -s reload nginx: [emerg] unknown directive "set_by_lua_block" in /usr/local/slardar/nginx/conf/slardar/service.conf:19

yejingx commented 7 years ago

@wangwj 检查下你的 lua-nginx-module 版本是否大于 v0.9.17。

wangwj commented 7 years ago

@yejingx 感谢回复,我直接用的是maser源码编译的,我已经确认过了,set_by_lua 也是不能用的,我看了我们的编译的依赖版本配置0.10.6rc1,配置如下,确实无法识别,我也是比较纳闷,原理上应该是支持的 V_PCRE=8.39 V_NGINX=1.9.15 V_LUAJIT=2.1-20150223 V_LUA_CJSON=2.1.0 V_NGX_LUA_MODULE=0.10.6rc1 V_CMSGPACK=f5b838ac552cbada957749d6938cd96a4e7a1f62 V_LUASOCKET=3.0-rc1

wangwj commented 7 years ago

估计是找到问题了,应该是编译少ndk的相关东西,https://github.com/simpl/ngx_devel_kit

yejingx commented 7 years ago

恩,看到文档里的说明了:

This directive requires the ngx_devel_kit module.