Proxy pass set body on if

Francis Daly francis at daoine.org
Sun Feb 21 15:54:17 UTC 2021


On Tue, Feb 16, 2021 at 10:00:47AM -0500, sanflores wrote:

Hi there,

> I have an Angular app and need to use puppeteer for SSR. In order to make it
> work I need to send the request with the body but I can't figure how to make
> these things work together. 

Can you see, which part is failing? Is it "you set the body, but it is
not what you expect"; or something else?

If you "tcpdump" the port-3000 traffic, do you see anything interesting?

>         if ($limit_bots = 1){
>                 proxy_pass http://localhost:3000/puppeteer/download/html/;

I get:

nginx: [emerg] "proxy_pass" cannot have URI part in location given by
regular expression, or inside named location, or inside "if" statement,
or inside "limit_except" block

(And more failures, after changing that. Generally: there are limited
things that you can do inside an "if" block.)

If you remove that "if", do things work differently for you?

>                 proxy_method GET;
>                 proxy_set_header content-type "application/json";
>                 proxy_pass_request_body off;
>                 proxy_set_body "{\"url\":\"https://$request\"}";
>         }

http://nginx.org/r/$request

That is probably not the variable that you want to use.

Maybe some combination of $server_name or $host, and $request_uri,
is more useful?

> The idea would be to redirect bots to the static html that will be provided
> by puppeteer runing in another server, and adding proxy_server inside an if
> is deprecated. I should be using a rewrite statement... but I can't set the
> body.

Reverse the test?

  if ($is_a_bot) {
    return / rewrite / whatever
  }
  proxy_pass ...

Good luck with it,

	f
-- 
Francis Daly        francis at daoine.org


More information about the nginx mailing list