Post_action to a backend server


#1

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


#2

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.


#3

Perfect, thank you very much Maxim!
Paul Bowsher


#4

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 :slight_smile:

Paul Bowsher


#5

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