proxy_pass in post_action location does not send any http request

classic Classic list List threaded Threaded
3 messages Options
xrd
Reply | Threaded
Open this post in threaded view
|

proxy_pass in post_action location does not send any http request

xrd
Hi

I am trying to configure NGINX to send another http request after successful
completion of the original proxied request, in order to count statistics
etc'
I am using post_action with proxy_pass as following:

 location / {
        proxy_http_version 1.1;
        proxy_set_header HOST $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Port 1061;
        proxy_set_header X-Forwarded-Host $host:1061;
        proxy_set_header X-Forwarded-Server $host:1061;
        proxy_read_timeout 86400;
        proxy_max_temp_file_size 0;
        proxy_set_header Connection "";

        set $backend rack-storage-radosgw:8802;

        proxy_pass http://$backend;
   
        post_action /send_event;
  }

  location /send_event {
        proxy_method POST;
        set $s3_proxy_request
s3-proxy-manager:8946/internal/api/v3/s3proxies/actions/raise_event;
        proxy_pass http://$s3_proxy_request;
   }


   The request in location / is sent to rack-storage-radosgw.service.strato
and is completed successfully, but the request to s3-proxy-manager is not
sent at all. I used tcpdump to capture any traffic on port 8946 and no
traffic arrived. I also checked that send_event location is entered by code,
and it does ( using rewrite_by_lua_block).
    What am i doing wrong?
    Thanks

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,286384,286384#msg-286384

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: proxy_pass in post_action location does not send any http request

Francis Daly
On Tue, Dec 03, 2019 at 04:48:23AM -0500, jacks wrote:

Hi there,

since no-one else has answered this yet...

>     What am i doing wrong?

Without me trying to be clever about it: you're asking for help about
post_action.


I think that the post_action directive is only documented in
src/http/ngx_http_request.c, and that is intentional.

If that C-code is not enough to make it totally clear to you what you
can and cannot safely do with post_action, then you should not use
post_action.


(As it happens, that C code is not enough to make it clear to me
what I can and cannot safely do with post_action, and so I do not use
post_action.)


> I am trying to configure NGINX to send another http request after successful
> completion of the original proxied request, in order to count statistics
> etc'

I don't have a good answer that involves post_action.

I would probably post-process the access log file, if I had need to do
that sort of thing.

Or maybe something involving the "mirror" module (if "after successful
completion" was not important here).


You're welcome to wait for a better answer; but given the status of
post_action, I will be (pleasantly) surprised if one is forthcoming.

Cheers,

        f
--
Francis Daly        [hidden email]
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
xrd
Reply | Threaded
Open this post in threaded view
|

Re: proxy_pass in post_action location does not send any http request

xrd
In reply to this post by xrd
Hi, jacks.

I use post_action for something similar to this for keeping track of users
who download files. I've got a location for the /download entry point like
this:

  location ~ /download/ {
    proxy_pass http://app_pool;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    post_action @finished;
  }

  # for mod_zip and x-accel-redirect requests, proxying the
  # request to S3 to fulfill the zip manifest or the x-accel-redirect URI
  location ~
"^/s3-proxy/(?<s3_bucket>.[a-z0-9][a-z0-9-.]*.s3.amazonaws.com)/(?<path>.*)$"
{
    internal;

    resolver 8.8.8.8 valid=30s; # Google DNS
    resolver_timeout 10s;

    proxy_http_version 1.1;
    proxy_set_header Host $s3_bucket;
    proxy_set_header Authorization '';

    # remove amazon headers
    proxy_hide_header x-amz-id-2;
    proxy_hide_header x-amz-request-id;
    proxy_hide_header Set-Cookie;
    proxy_ignore_headers "Set-Cookie";

    # bubble errors up
    proxy_intercept_errors on;

    proxy_pass https://$s3_bucket/$path?$args;
  }


  location @finished {
    internal;

    rewrite ^
/download/finish/$sent_http_x_download_log_id?bytes=$body_bytes_sent&status=$request_completion;
  }

  location ^~ /download/finish {
    proxy_pass http://$download_postback_hostname; # variable map declared
elsewhere
  }

This does work for sending the post_action response after the /download
request is served- with one notable caveat! It does not work for
X-Accel-Redirect responses from my app server. As far as I can tell, the
post_action is either (1) never called in that case, or (2) has some other
issue I have been able to figure out. I've dug around in the C source for
Nginx, but it gets to a spot pretty quick where I'm in over my head.

Although I've been living with this since 2017, here's my mailing list post
regarding the issue from 2018: https://forum.nginx.org/read.php?2,278529

I've considered trying to engage Nginx for commercial support on this one
issue, but I'm not sure what kind of appetite they may have for these types
of issues.

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,286384,286703#msg-286703

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx