0

I'm using YARP Reverse Proxy in .NET 7 but I'm encountering the following problem.

I've a route that matches

"Path": "/wiki/{*any}"      to 
"Address": "https://it.wiktionary.org/".

Thus, if I digit

localhost:5000/wiki/prova

it loads the page

https://it.wiktionary.org/wiki/prova        

as intended.

However, when it tries to fetch the resources contained in https://it.wiktionary.org/wiki/prova, it searches them on localhost:5000 and thus it can't find them. For example it looks for

http://localhost:5000/w/load.php?lang=it&modules=startup&only=scripts&raw=1&skin=vector

instead of looking for

https://it.wiktionary.org/w/load.php?lang=it&modules=startup&only=scripts&raw=1&skin=vector

and of course it cannot to find it. Am I missing some options?

  • No, YARP works as expected here. It will only proxy requests, if you want to change the response to match your url structure you will have to do it yourself. There was a question about it on github where they said it was out of scope for the project. https://github.com/microsoft/reverse-proxy/issues/1691#issuecomment-1136303384 – Karl-Johan Sjögren Aug 10 '22 at 06:36
  • Thank you for the answer. I thought this was more a request problem that a response one. I thought there was something like "when you need to reference a root-relative resource, get it from the actual domain" – Alessandro Martinelli Aug 10 '22 at 06:53
  • 2
    The problem in your case is that you are proxying from a subdirectory while the site you are proxying to expects resources from the root. So they reference stuff from the root, which as you've seen goes to `/w/load.php`, and that part of your website isn't handled by YARP. If you setup your proxy from `/` instead of `/wiki/` it should work as expected but that isn't always feasible of course. – Karl-Johan Sjögren Aug 10 '22 at 07:04
  • Yes ,you're right .I'm ignroing this layer .I thought it would respond to the original path instead of the proxy site .Thank you ! @Karl-Johan Sjögren – Chen Aug 10 '22 at 07:21
  • @Karl-JohanSjögren you're right, if I match {*any} to https://it.wiktionary.org/, then when I browse localhost:5000/wiki/prova not only the correct page is returned but also all the resources are loaded correctly. The problem is I'd like to have a number of applications app1, app2 etc, each one listening on a ip:port, and use the reverse proxy to make this transparent to the user, that should have the impression of using a single web app. And I need a way of discriminating if a given request must be forwarded to app1 or to app2. – Alessandro Martinelli Aug 10 '22 at 07:47
  • 1
    No, YARP won't give you that out of the box for most cases. It is just a proxy, you need something more. – Karl-Johan Sjögren Aug 10 '22 at 07:59

0 Answers0