Nginx multiple upstream servers on the same domain via diferent url

Posted by Barry on Server Fault See other posts from Server Fault or by Barry
Published on 2011-01-05T18:11:51Z Indexed on 2011/01/05 18:56 UTC
Read the original article Hit count: 390

Filed under:

Hello. I am trying to rout trafic to different upstream servers (that serve different applications and not for load balancing). The incoming trafic has the same domain name but different URL. Here is an example of my configuration:

http {
upstream  backend1 {
    server   127.0.0.1:8080 fail_timeout=0;
    server   127.0.0.1:8081 fail_timeout=0;

}

upstream backend2 {
    server   127.0.0.1:8090 fail_timeout=0;
    server   127.0.0.1:8091 fail_timeout=0;
}


server
{
    listen   80;
    server_name my_server.com;
    root /home/my_server;

    location /serve_me
    {
        fastcgi_pass backend1;
        include fastcgi_params;
    }

    location /
    {
        fastcgi_pass backend2;
        include fastcgi_params;
    }
}
}

It seems that whatever trafic comes in (including "my_server.com/serve_me") goes to backend2. How do I make queries that start with /serve_me to be directed to backend1?

Thanks, Barry.

© Server Fault or respective owner

Related posts about nginx