nginx reverse proxy based on response header

404 Views Asked by At

I have a setup of the website that powered by 2 web applications under the hood.

One application (fast) is supposed to handle catalog pages.
Another application (slow) is supposed to handle customer/cart/checkout pages.

Both applications should run on the same host:
example.com:80 (fast) and example.com:8000 (slow)
Of course, port 8000 is not exposed for the visitor and used internally by nginx.

I want that web requests reach slow application only if fast application returned specific response header, for example X-catalog-not-found.

The expected result is following:

  1. all requests go to fast application example.com:80
  2. if fast application found a product by uri - it renders the page
  3. if fast application did not find a product by uri - it sends empty body and response header X-catalog-not-found
  4. based on the header received in prev step, nginx performs proxy pass to slow application example.com:8000

I feel that ngx_http_proxy_module or/and nginx_upstream module should be used, but haven't found a working solution after reading the docs.

0

There are 0 best solutions below