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 want to do the following: I have nginx that redirects to tomcat, so the config is something like this:


    upstream miserver.com {
         server localhost:8080;
    }


    server {

        listen      0.0.0.0:80;
        location / {
            proxy_pass http://miserver.com/mywar-web-0.4/convert;
        }
   }

What I want to do is that nignx hits to upstreams, and only takes into account the response of one of them. This is because I want to test a new version of the war, but I still want to continue with the old one (the new one will log the information in a file).

For example, I want to have:


    upstream miserver.com {
         server localhost:8080;
    }

    server {

        listen      0.0.0.0:80;
        location / {
            proxy_pass http://miserver.com/mywar-web-0.4/convert;
            proxy_pass http://miserver.com/mywar_testing-web-0.4/convert;
        }
   }

and when there is a hit on "/", then nginx hits: - mywar-web-0.4 - mywar_testing-web-0.4

but only the resonpse of mywar-web-0.4 is used.

share|improve this question
1  
You cant have 2 redirects/proxies for the one location.. –  Arenstar Nov 15 '10 at 15:06

3 Answers 3

up vote 0 down vote accepted

What you basically want is to have a single client request result in nginx making two requests to the backend servers, but only return the result of one of such requests back to the client. This is very unusual, and it's not something that's generally supported.

  • You might want to try to play some tricks with error_page. You would want to make the first request (the reply for which is to be discarded), and then catch its status code as an error, and then use a named location (the one that starts with @ and does not rewrite $uri) to handle the subsequent request, which will be returned to the client. Not sure if you can specify error_page 200, if not, then you might have to modify your app (the reply of which is to be discarded) to return some actual error code instead.

  • Alternatively, you may try using some kind of a filter module, like ngx_http_addition_module and add_after_body directive. Although this is an official module that's already part of the source-code distribution of nginx, it requires recompilation, and it would also result in two replies given back to the user, so you'd have to modify your app anyways.

share|improve this answer

I load balance 4 tornado servers with this configuration.

upstream frontends {
    server 127.0.0.1:8888;
    server 127.0.0.1:8889;
    server 127.0.0.1:8890;
    server 127.0.0.1:8891;
}
server { 
    listen 80;
    location / {
        proxy_pass http://frontends;
    }
}

Requests are distributed among each server in the "frontends" list and if one is down it will be ignored until it reachable.

In your example you could have each of your wars handle part of the traffic at / if they are each listening on a different port.

Check the Upstream module documentation for more information.

share|improve this answer
1  
I don't want to distributer the request. I want that all the servers recieve the same requests. –  tzulberti Nov 16 '10 at 15:34
    
Neither upstream nor proxy_pass will let you do that. When a client connects it opens 1 socket to nginx, nginx opens a socket with the server it is proxying and funnels the response back through that. There wouldn't be a situation where it opens a second socket to your other server and just discards the response. –  Dan R Nov 17 '10 at 20:34
    
If you are looking for a way to test your new war with the same traffic. Maybe you could use the access logs to replay the traffic against /testing/ or something similar. –  Dan R Nov 17 '10 at 20:35

Does This work for you?

 upstream miserver.com {
         server localhost:8080;  <- This is Live mywar-web-0.4
         server localhost:8081;  <- This is Testing mywar_testing-web-0.4
    }

    server {
        listen      0.0.0.0:80;
        location / {
            proxy_pass http://miserver.com;
        }
   }
Not sure if you can do this, and still know what backend your using

Hope this helps :D

share|improve this answer
    
That works. But I have to change the location. I want to use the same location for the 2 upstreams. –  tzulberti Nov 16 '10 at 15:35
    
You mean so that they overlap?? If you try to do that.. basically, one request will go to live, another request to testing.. ( how will you know) which one your on??? –  Arenstar Nov 16 '10 at 15:41
    
Is that better?? i updated my answer.. –  Arenstar Nov 16 '10 at 15:54
1  
In that case, the localhost:8080 will answer and if it is down, then the localhost:8081 will be used. I want that the 2 servers get the request, not just one of them –  tzulberti Nov 16 '10 at 20:16
    
Noo it will be shared, between requests ( alternating ).. :D –  Arenstar Nov 16 '10 at 21:20

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.