Skip to content

An attempt to use nginx as redirect balancer using lua-nginx-module

Notifications You must be signed in to change notification settings

whatvn/nginx_redirect_balancer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 

Repository files navigation

nginx_redirect_balancer"

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

Usage

  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 192.168.10.226 weight=5;
        server 192.168.10.225 weight=1;
	server google.com 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 http://192.168.10.226 or http://192.168.10.225 or http://google.com/ 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

About

An attempt to use nginx as redirect balancer using lua-nginx-module

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages