Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer 1

You can have multiple location statements each with it's own upstream

location /cas/ {
  proxy_pass              http://lb; 
  }

location /web/ {
    proxy_pass              http://2b;    
  }

location /mail/ {
    proxy_pass              http://3b;    
  }

You can also use if statements that checks the $request_uri variable and uses that to decide what upstream to pass the request to.

if ($request_uri ~* "^/(.+?)/context")
{
  proxy_pass   http://domain.com$request_uri;
  break;
}
share|improve this answer
    
actually it's a bad idea to put proxy_pass inside if {} –  DukeLion Aug 19 '13 at 9:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.