I am trying to host a single page application (Angular), and redirect all calls to /api to localhost:5000 where by backend service is.
By deleting “try_files” the reverse_proxy works as it should. However without this, I cant acces familiengrondahl.dk/something, as this is not redirected to my index.html.
I would love for all request to be forwarded to index.html except calls to /api*, but can’t find any configuration to resolve this.
4. Error messages and/or full log output:
no error messages
As I would think this is a normal usecase I really hope someone can help me out
As an explanation: the try_files directive is special in that it’s a shortcut for rewrite with a try_files matcher; it doesn’t support matchers because it itself involves a matcher internally. So instead, we need to explicitly use the expanded form of try_files, i.e. using a rewrite.
Yep, that’s true, that’ll probably work too. Reads better too!
To clarify, route will essentially override the order in which the directives are handled, to be the order in which they’re listed inside the block.
By default, rewrite (and therefore try_files) are ordered to be handled before reverse_proxy, because it’s very common for people to want to rewrite requests before they reach an upstream server.