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?
NGINX rewrite rules are used to change entire or a part of the URL requested by a client. The main motive for changing an URL is to inform the clients that the resources they are looking for have changed its location apart from controlling the flow of executing pages in NGINX.
The proxy_pass setting makes the Nginx reverse proxy setup work. The proxy_pass is configured in the location section of any virtual host configuration file. To set up an Nginx proxy_pass globally, edit the default file in Nginx's sites-available folder.
The rewritten URL uses two NGINX variables to capture and replicate values from the original request URL: $scheme is the protocol (http or https) and $request_uri is the full URI including arguments. For a code in the 3xx series, the url parameter defines the new (rewritten) URL.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With