Forum: NGINX post_action to a backend server

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ff870982e84d7f6dd6e1af91ab4e3797?d=identicon&s=25 Paul Bowsher (Guest)
on 2009-01-24 20:32
(Received via mailing list)
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
A8108a0961c6087c43cda32c8616dcba?d=identicon&s=25 Maxim Dounin (Guest)
on 2009-01-25 13:13
(Received via mailing list)
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 Dounin
Ff870982e84d7f6dd6e1af91ab4e3797?d=identicon&s=25 Paul Bowsher (Guest)
on 2009-01-25 13:32
(Received via mailing list)
Perfect, thank you very much Maxim!
Paul Bowsher
Ff870982e84d7f6dd6e1af91ab4e3797?d=identicon&s=25 Paul Bowsher (Guest)
on 2009-01-25 13:42
(Received via mailing list)
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
23a07204927fd26a5263d1731709a86c?d=identicon&s=25 Rob Mueller (Guest)
on 2009-01-27 03:44
(Received via mailing list)
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
This topic is locked and can not be replied to.