# Post\_action to a backend server

**URL:** <https://www.ruby-forum.com/t/post-action-to-a-backend-server/158556>\
**Category:** NGINX\
**Created:** [January 24, 2009, 8:32pm UTC](https://www.ruby-forum.com/t/post-action-to-a-backend-server/158556 "2009-01-24T20:32:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_Bowsher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a8b319/32.png) [@Paul\_Bowsher](https://www.ruby-forum.com/u/Paul_Bowsher)\
**Post date:** [January 24, 2009, 8:32pm UTC](https://www.ruby-forum.com/t/post-action-to-a-backend-server/158556/1 "2009-01-24T20:32:15Z")

</div>

Hi,  
I am currently using nginx on frontend to proxy all requests to an  
apache  
backend. I want to use post\_action to callback upon completion of a  
request.

The location I want to callback to is on the backend. Currently I have  
the  
following:

```
    location / {
        proxy_pass http://test;
        post_action /test_post.php;
    }

    location = /test_post.php {
        proxy_pass http://test;
        internal;
    }

```

Normal proxying works fine, but nginx does not appear to ever make the  
callback to test\_post.php. Removing the test\_post.php location results  
in a  
Redirect cycle error in my log. Does anyone know how to resolve this?

Kind regards,

Paul Bowsher

---

<div class="post-metadata">

**Author:** ![Paul\_Bowsher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a8b319/32.png) [@Paul\_Bowsher](https://www.ruby-forum.com/u/Paul_Bowsher)\
**Post date:** [January 25, 2009, 1:13pm UTC](https://www.ruby-forum.com/t/post-action-to-a-backend-server/158556/2 "2009-01-25T13:13:11Z")

</div>

Hello!

On Sat, Jan 24, 2009 at 07:19:10PM +0000, Paul Bowsher wrote:

> ```
> }
> 
> location = /test_post.php {
> proxy_pass http://test;
> 
> ```

- 

```
        proxy_pass http://test;

```

- 

```
        proxy_pass http://test/test_post.php;

```

> ```
> internal;
> }
> 
> ```
> 
> Normal proxying works fine, but nginx does not appear to ever make the  
> callback to test\_post.php. Removing the test\_post.php location results in a  
> Redirect cycle error in my log. Does anyone know how to resolve this?

See above. The proxy\_pass without uri component uses original  
request uri (and post\_action doesn’t invalidate it currently). So  
you have to use proxy\_pass with explicitly set uri for this to  
work.

Maxim D.

---

<div class="post-metadata">

**Author:** ![Paul\_Bowsher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a8b319/32.png) [@Paul\_Bowsher](https://www.ruby-forum.com/u/Paul_Bowsher)\
**Post date:** [January 25, 2009, 1:32pm UTC](https://www.ruby-forum.com/t/post-action-to-a-backend-server/158556/3 "2009-01-25T13:32:02Z")

</div>

Perfect, thank you very much Maxim!  
Paul Bowsher

---

<div class="post-metadata">

**Author:** ![Paul\_Bowsher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a8b319/32.png) [@Paul\_Bowsher](https://www.ruby-forum.com/u/Paul_Bowsher)\
**Post date:** [January 25, 2009, 1:42pm UTC](https://www.ruby-forum.com/t/post-action-to-a-backend-server/158556/4 "2009-01-25T13:42:36Z")

</div>

As a follow up, is there any way to get the amount of data sent in the  
upstream request? I can then compare to content-length and see if the  
request completed successfully or not. I have proxy\_set\_header  
X-Original-Length $content\_length, but this doesn’t appear on the  
post\_action whereas proxy\_set\_header X-Original-Uri $request\_uri does.

Thanks for your help 🙂

Paul Bowsher

---

<div class="post-metadata">

**Author:** ![Paul\_Bowsher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a8b319/32.png) [@Paul\_Bowsher](https://www.ruby-forum.com/u/Paul_Bowsher)\
**Post date:** [January 27, 2009, 3:44am UTC](https://www.ruby-forum.com/t/post-action-to-a-backend-server/158556/5 "2009-01-27T03:44:54Z")

</div>

As a follow up, is there any way to get the amount of data sent in the  
upstream request? I can then compare to content-length and see if the  
request completed successfully or not. I have proxy\_set\_header  
X-Original-Length $content\_length, but this doesn’t appear on the  
post\_action whereas proxy\_set\_header X-Original-Uri $request\_uri does.  
You mean you want the number of bytes sent to the client? If so, then  
yes we do this with:

```
  proxy_set_header RateBytes $body_bytes_sent;

```

One thing to be aware of though, is that this is bytes sent by nginx.  
Your OS might have quite large TCP buffers, so nginx might send the  
whole response to the TCP buffers, but the client might kill the  
connection before it’s all downloaded. I don’t think there’s any sane  
way of detecting that other than making your TCP buffers small  
(potential performance implications), or using some lower level tracking  
method.

Rob
