0

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.

dvolik
  • 11
  • 3
  • Is it an option to work with default http status codes like http 404? – Timo Stark Apr 08 '20 at 11:44
  • For example, there are 2 urls: example.com/running-short.html and example.com/cart The fast application will find a product (by uri /running-short.html) and render it. But it will not find a product by uri /cart and will send X-catalog-not-found header instead, which then should be handled by nginx and passed to the slow application – dvolik Apr 08 '20 at 12:07
  • Yeah got that. There would be a simple solutions using error_page directive in case your application is able to send a http 404 status code as a response to the first request to the `fast`backend in case the product was not foud by uri. Would that work? – Timo Stark Apr 08 '20 at 12:09
  • 1
    hm, sounds genius :) will try it. I also want it transparently handle all HTTP requests, not just GET/HEAD – dvolik Apr 08 '20 at 14:15
  • Is it working with the error_page? Can write an answer post about it – Timo Stark Apr 09 '20 at 22:37

0 Answers0