# Sending Traffic to another Server/Port/IP asynchronously

**URL:** <https://www.ruby-forum.com/t/sending-traffic-to-another-server-port-ip-asynchronously/216659>\
**Category:** NGINX\
**Created:** [February 10, 2012, 5:26am UTC](https://www.ruby-forum.com/t/sending-traffic-to-another-server-port-ip-asynchronously/216659 "2012-02-10T05:26:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [February 10, 2012, 5:26am UTC](https://www.ruby-forum.com/t/sending-traffic-to-another-server-port-ip-asynchronously/216659/1 "2012-02-10T05:26:28Z")

</div>

I have nginx as the HTTP server.

I wanted to write a module which asynchronously send all the traffic to  
another IP or PORT where my analytics server will be running. I dont  
want to create any lag in serving HTTP requests.

Is there any existing module which I can use as a base and modify to  
meet my requirements.

Any help would be greatly appreciated.

Thanks

Posted at Nginx Forum:

> **[Sending Traffic to another Server/Port/IP asynchronously](https://forum.nginx.org/read.php?2,222196,222196#msg-222196)**
>
> I have nginx as the HTTP server. I wanted to write a module which asynchronously send all the traffic to another IP or PORT where my analytics server will be running. I dont want to create any lag in serving HTTP requests. Is there any existing...

---

<div class="post-metadata">

**Author:** ![rishabh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ea5d25/32.png) [@rishabh](https://www.ruby-forum.com/u/rishabh)\
**Post date:** [February 10, 2012, 5:51am UTC](https://www.ruby-forum.com/t/sending-traffic-to-another-server-port-ip-asynchronously/216659/2 "2012-02-10T05:51:49Z")

</div>

On Fri, Feb 10, 2012 at 6:25 AM, rishabh [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thanks

Try post\_action

---

<div class="post-metadata">

**Author:** ![rishabh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ea5d25/32.png) [@rishabh](https://www.ruby-forum.com/u/rishabh)\
**Post date:** [February 10, 2012, 7:20am UTC](https://www.ruby-forum.com/t/sending-traffic-to-another-server-port-ip-asynchronously/216659/3 "2012-02-10T07:20:51Z")

</div>

Thanks, post\_action works like a charm.

Just one problem. Nothing is getting logged access\_log if i use  
post\_action ! whats the co-relation ?

Posted at Nginx Forum:

> **[Re: Sending Traffic to another Server/Port/IP asynchronously](https://forum.nginx.org/read.php?2,222196,222200#msg-222200)**
>
> I have nginx as the HTTP server. I wanted to write a module which asynchronously send all the traffic to another IP or PORT where my analytics server will be running. I dont want to create any lag in serving HTTP requests. Is there any existing...

---

<div class="post-metadata">

**Author:** ![rishabh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ea5d25/32.png) [@rishabh](https://www.ruby-forum.com/u/rishabh)\
**Post date:** [March 19, 2012, 11:08am UTC](https://www.ruby-forum.com/t/sending-traffic-to-another-server-port-ip-asynchronously/216659/4 "2012-03-19T11:08:40Z")

</div>

That logging issue was a mistake. All the access\_log directive need to  
be in a single location/server block.

After a lot of testing. I found an issue.

The processing time of post\_action is added to the response time. hence  
delaying the response.

Here is how i have used post\_action to log.

http {

server {

location / {  
proxy\_pass [http://upstream123](http://upstream123);  
post\_action @loglua;  
}

location @loglua {  
set $log ‘’;  
rewrite\_by\_lua\_file /nginx/mylua.lua;  
logformat format1 ‘$log’;  
access\_log /var/log/nginx/newlog.log format1;  
}  
}  
}

Posted at Nginx Forum:

> **[Re: Sending Traffic to another Server/Port/IP asynchronously](https://forum.nginx.org/read.php?2,222196,224021#msg-224021)**
>
> I have nginx as the HTTP server. I wanted to write a module which asynchronously send all the traffic to another IP or PORT where my analytics server will be running. I dont want to create any lag in serving HTTP requests. Is there any existing...

---

<div class="post-metadata">

**Author:** ![rishabh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ea5d25/32.png) [@rishabh](https://www.ruby-forum.com/u/rishabh)\
**Post date:** [March 19, 2012, 11:37am UTC](https://www.ruby-forum.com/t/sending-traffic-to-another-server-port-ip-asynchronously/216659/5 "2012-03-19T11:37:19Z")

</div>

On Monday 19 March 2012 14:08:46 rishabh wrote:  
[…]

> After a lot of testing. I found another issue.
> 
> The processing time of post\_action is added to the response time. hence  
> delaying the response.

It doesn’t delay response, but block the connection, and that’s why we  
don’t  
recommend to use it. The best way to gather statistics is parsing access  
log  
files.

wbr, Valentin V. Bartenev

---

<div class="post-metadata">

**Author:** ![rishabh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ea5d25/32.png) [@rishabh](https://www.ruby-forum.com/u/rishabh)\
**Post date:** [March 19, 2012, 11:09am UTC](https://www.ruby-forum.com/t/sending-traffic-to-another-server-port-ip-asynchronously/216659/6 "2012-03-19T11:09:17Z")

</div>

## rishabh Wrote:

> Thanks, post\_action works like a charm.
> 
> Just one problem. Nothing is getting logged  
> access\_log if i use post\_action ! whats the  
> co-relation ?

That logging issue was a mistake. All the access\_log directive need to  
be in a single location/server block.

After a lot of testing. I found another issue.

The processing time of post\_action is added to the response time. hence  
delaying the response.

Here is how i have used post\_action to log.

http {

server {

location / {  
proxy\_pass [http://upstream123](http://upstream123);  
post\_action @loglua;  
}

location @loglua {  
set $log ‘’;  
rewrite\_by\_lua\_file /nginx/mylua.lua;  
logformat format1 ‘$log’;  
access\_log /var/log/nginx/newlog.log format1;  
}  
}  
}

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,222196,224022#msg-224022](http://forum.nginx.org/read.php?2,222196,224022#msg-224022)
