January 10, 2020 04:29PM
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.
Subject Author Posted

proxy_pass in post_action location does not send any http request

jacks December 03, 2019 04:48AM

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

Francis Daly December 11, 2019 03:48PM

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

clintmiller January 10, 2020 04:29PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 170
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready