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'm trying to replicate the traffic that one specific nginx server receives to two servers. The goal is not to load-balance, but to replay the same input on all nginx servers.

An example: Nginx receives a HTTP POST. I want to send this same POST to other servers.

** UPDATE **

The situation is easy and non-complex. I just need to resend the POST data (or GET or any request data) to another server IP (it also running a nginx instance). Just it.

USER -> POST DATA -> NGINX INSTANCE ----REDIRECT ---> SERVER 1 AND SERVER 2

share|improve this question
1  
Can you expand on your architecture? What are the other two servers? Is there a shared DB, shared filesystem, etc.? Does the POST write to the DB, to the filesystem, what? Actually, what are you trying to accomplish that can't be done with clustered filesystems and database instances? –  cjc Aug 1 '12 at 19:35
    
I rephrased you question to more accurately reflect what you seem to be asking. –  gWaldo Aug 1 '12 at 19:43
1  
This type of behaviour is sometimes used in A/B testing –  gWaldo Aug 1 '12 at 19:43
2  
That is not the way to go, you're breaking HTTP, w3.org/Protocols/rfc2616/rfc2616.html –  Daniel Prata Almeida Aug 1 '12 at 19:57
    
I've seen this type of thing asked about before. I think that what you want to look into can be searched for as "http replay". –  gWaldo Aug 1 '12 at 20:02

4 Answers 4

I don't believe you can do this with nginx by itself; a quick perusal of the relevant bits of the nginx documentation (upstream and proxy directives) doesn't suggest you can. As noted in comments, this also breaks HTTP, as there's no clarity on which of the two rear servers will respond.

One alternative is to use something like varnish and do a replay to the second rear server using varnishreplay:

https://www.varnish-cache.org/docs/2.1/reference/varnishreplay.html

I haven't used it, so I don't know if you can make it replay the traffic nearly simultaneously with the first rear server.

share|improve this answer

Use central storage like an NFS server and each nginx web node mounts the NFS share (file-level). Or use a cluster file system like OCFS2 and each web node mounts the LUN/partition (block-level).

share|improve this answer
    
The POST request doesn't necessarily write things to the filesystem. We need clarification on the OP's architecture. –  cjc Aug 1 '12 at 19:36
    
@cjc, True, I was reading between the lines... –  HTTP500 Aug 1 '12 at 19:37

What you want to use is something like EM-Proxy[1]. It easily handles splitting http requests across any number of servers. It also correctly handles returning data from only the live server and blocking the others so the user doesn't get multiple responses.

[1] https://github.com/igrigorik/em-proxy/

share|improve this answer

I was able to replicate using post_action state.

upstream main_upstream {
least_conn;
server 192.168.9.10:80;
keepalive 1024;
}

server {
listen 80;
server_name _;
client_body_buffer_size 1512k;
client_max_body_size 10m;

location /1/ {
fastcgi_pass main_upstream;
post_action @replayevent ;

}
# Send the post_action request to a FastCGI backend for logging.
location @replayevent {
fastcgi_pass 192.168.9.14:80;
}

Now it send data two servers.

If your upstream do not support fastcgi (happened in my case), replace with proxy_pass.

Nginx replicate incoming post traffic to multiple upstream servers

share|improve this answer

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.