Created
June 19, 2014 11:05
-
-
Save first-developer/0747c508aed75270cddd to your computer and use it in GitHub Desktop.
Load balancing using weight with nginx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # | |
| # moche car on fait une 2nd req HTTP | |
| # mais ça doit fonctionner nickel | |
| # | |
| # | |
| upstream lb { | |
| server 127.0.0.1:1111/1a/ weight=3; | |
| server 127.0.0.1:1111/1b/ weight=2; | |
| server 127.0.0.1:1111/1c/ weight=5; | |
| server 127.0.0.1:1111/1d/ weight=1; | |
| server 127.0.0.1:1111/1e/ weight=5; | |
| } | |
| http { | |
| listen 160.92.1.1:80; | |
| server_name webmail.orange.fr; | |
| location / { | |
| proxy_pass http://lb; | |
| } | |
| } | |
| http { | |
| listen 127.0.0.1:1111; | |
| location ~ ^/([^/]+)/(.*)+ { | |
| rewrite . http://webmail$1.orange.fr/$2 redirect; | |
| } | |
| } | |
| # | |
| # | |
| # Dans ce cas on va faire du lua, simple | |
| # | |
| # | |
| http { | |
| listen 160.92.1.1:80; | |
| server_name webmail.orange.fr; | |
| set_by_lua $lb " | |
| local t = { '1a', '1a', '1b', '1b', '1b', '1b', '1c', '1c', '1c', '1c', '1c' } | |
| return(t[ math.random( #t ) ]) | |
| "; | |
| rewrite . http://webmail$lb1$lb2.orange.fr$request_uri redirect; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment