loadbalancing with difference nginx location context and backend context

Posted by robinmag on Server Fault See other posts from Server Fault or by robinmag
Published on 2010-05-14T12:58:09Z Indexed on 2010/05/14 13:04 UTC
Read the original article Hit count: 484

Hi,

I used nginx and upstream module for load balancing with the following config

upstream lb {
  server 127.0.0.1:8080;
  server 127.0.0.1:8081;
 }
 server {
  listen 88;
  server_name localhost;

  location /cas/ {
    proxy_pass              http://lb;
    proxy_redirect          off;
    proxy_connect_timeout   2;
    proxy_set_header        Host            $host;
    proxy_set_header        X-Real-IP       $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
  }
}

the problem is the "location /context/" have to match to the context of backend server so when i request localhost/context/index.html then nginx routes it to 127.0.0.1:8080/context/index.html or 127.0.0.1:8080/context/index.html.

Is it possible to have difference backend context and nginx location for example with "location /" nginx will routes the request to 127.0.0.1:8080/context/index.html or 127.0.0.1:8080/context/index.html

Thank you.

© Server Fault or respective owner

Related posts about nginx

Related posts about load-balancing