Rewrite request on Nginx from GET to POST with body (for tracking pixel)

benyamin_d picture benyamin_d · Feb 28, 2017 · Viewed 7.3k times · Source

I'm trying to figure out if there's an easy way to convert a tracking pixel request that gets to Nginx into a POST that will go to an upstream with some added body.

for exmaple, if I get a GET request for http://domain.com/track/mail-id.gif, I'd like to configure Nginx to convert it to a POST that goes to http://upstream/mail-id with some body (let's say status:opened).

how can it be done?

Answer

Azat Khadiev picture Azat Khadiev · Nov 10, 2017

Just wanted to add a more detailed example:

location /track/mail-id.gif {
    proxy_pass http://upstream/mail-id;
    proxy_method POST;
    proxy_set_body "status:opened";
    # if needed
    # proxy_set_header Some-Header value;
}

Provided a url for proxy_pass here, so to ensure the exact behaviour requested.