An attempt to use nginx as redirect balancer using lua-nginx-module
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


An attempt to implement redirector inside nginx which works similar to py-balancer


  1. Install nginx with lua-nginx-module and lua-upstream-module, and ngx_devel_kit
	./configure --with-ld-opt=-Wl,-rpath,/usr/local/lib --add-module=lua-nginx-module --add-module=lua-upstream-nginx-module --add-module=ngx_devel_kit
  1. Config your nginx likes this:
 upstream google {
        server weight=5;
        server weight=1;
	server weight=10;


  server {
        listen       80;
        server_name  localhost;
	location / {
	    # "google" is the name of your upstream configuration.
	    set $upstream "google";
            set_by_lua_file $res path/to/redirector.lua $upstream;
	    return 302 $res;


That's it. When pointing your browser to http://localhost/ , you will be redirect to or or based on weight configured in upstream block, if request contains additional uri or query strings, those things will be pass to redirect url too.

Status: everything is working now with help-of-agentzh