ASP.Net Core Reverse Proxy with different root

Viewed 16305

I am having problems proxying an ASP.NET Core MVC app.

My app is running on Kestrel on localhost:5000 and my Apache 2.4 reverse proxy is running on localhost:80. I want to proxy all requests from localhost:80/test to localhost:5000

Here is the httpd.conf part for the proxy:

...
<Location "/test">
   ProxyPass "http://localhost:5000"
   ProxyPassReverse "http://localhost:5000"
</Location>
...

The proxy works, however all links are broken. Like if I have an anchor that links to a controller named HomeController with the action About, the link returned from the proxy is localhost/Home/About instead of localhost/test/Home/About. The host is correct, it's the context root test that is missing.

What is the best practice to handle this? Is it a configuration in ASP.NET Core to specify the context root so that TagHelpers will take it into account? Or is it a configuration in Apache ProxyPass to rewrite links (really not a big fan of this)?

3 Answers

for .net core you could add this

app.UsePathBase(basePath);
app.UseRouting();
Related