Proxy pass set body on if

Francis Daly francis at
Mon Feb 22 21:11:27 UTC 2021

On Mon, Feb 22, 2021 at 02:15:42PM -0500, sanflores wrote:

Hi there,

I suspect that if I were doing this, I would probably pick one url that
is not otherwise used on my server (in this example, "/puppet/"), and
use that as a "stepping stone".

Then, if this request should be handled specially, rewrite to that url,
ad do the proxy_pass and friends in there.

There may be better ways, but this appears to give the desired response.

> So the question would be, what configuration would be needed in order to
> redirect the crawlers (based on $http_user_agent) to puppeteer modifying the
> body?

>     server {

Somewhere at "server" level, outside of other location{} blocks, add:

  if ($limit_bots = 1) { rewrite ^ /puppet/? break; }

  location = /puppet/ {
    proxy_pass http://localhost:3000/puppeteer/download/html/;
    proxy_method GET;
    proxy_set_header content-type "application/json";
    proxy_pass_request_body off;
    proxy_set_body "{\"url\":\"$scheme://$host$request_uri\"}";

Note that the variables in "proxy_set_body" do matter -- they relate to
the request received by this nginx.


Francis Daly        francis at

More information about the nginx mailing list