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

本秂侑毒 提交于 2019-12-12 18:03:52

问题


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?


回答1:


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.




回答2:


You should be able to use Nginx proxy functionality to achieve this, specifically with the proxy_method directive.

Something like:

location /track/mail-id.gif {
    proxy_pass http://upstream
    proxy_method POST
}

See http://nginx.org/en/docs/http/ngx_http_proxy_module.html for more information about Nginx proxy directives.



来源:https://stackoverflow.com/questions/42506941/rewrite-request-on-nginx-from-get-to-post-with-body-for-tracking-pixel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!