New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hosting behind reverse proxy with subdirectory #2302
Comments
Is the request forwarded with the url intact and you want to split it? UsePathBase works for that. |
Now I guess somebody needs to tell Kestrel that whatever it sees as / is in fact /app and it should generate URLs to other places accordingly. I'd like this to be configurable from the outside of the ASP.NET Core app because the path is determined by the hosting environment and not by the application itself. This could be through an environment variable. But AFAIR that isn't supported yet and the app has to call some method to add this behaviour. Adding this code doesn't do anything for me:
|
Did you put it first in the pipeline? |
Yes, the first instruction in the |
You need the reverse of UsePathBase, you're not trying to trim the path, you just need to set PathBase.
|
@Tratcher Did you mean one of these alternatives? With missing
And with
(Edit: No, these are wrong, too. Please correct.) |
Right, coding on my phone... Note that PathBase is the url root used when generating links, etc.. It is not a file path. That's why I set it to "/app". What's not working for you? |
I've tried this and it works! This is the code I need in apps hosted on my server. And I'd like it to be default for the ASP.NET Core framework.
My starter script sets these environment variables before running the dotnet command: (This is a simplified sample, the actual script is written in PHP.)
And these directives are used for the Apache proxy configuration: (Again, pseudo-variables.)
So nobody found the original issue on this topic and I haven't received any notifications from it recently, I guess it got lost. So this is now my official request to build this base path support into ASP.NET Core. This allows hosters to map an application into a subdirectory in the URL without modifications to the application code. The environment variable Maybe the older issue mentioned something like supporting |
@Tratcher My last reply took too long to write, so here's my answer to your reply.
It doesn't compile. The |
BTW, what happens when you add an ASP.NET (Core) application in a virtual subdirectory in IIS? Will that work without modifications to the app itself? Does the IIS integration handle what I have described here? |
The issue you're looking for is https://github.com/aspnet/Hosting/issues/1120. The main difference is that we expect the forwarded url to contain the path base. |
Might be worth doing this (reopen) so that we don't need to do this https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/proxy-load-balancer?view=aspnetcore-2.2#deal-with-path-base-and-proxies-that-change-the-request-path given the existence of Azure Front Door? @rynowak |
Re-opening but keeping in backlog. We'll re-triage this for a future release. Triage note: This is related to but distinct from #5898. The proxy deleted segments from the URL and we need to put them back. |
I take that back, #5898 (comment) already accounts for this. |
I'm pretty sure this is the inverse of PathBase. I'm having to add it back in order to get ~ to work. I'm taking http://staging.hanselman.com/blog and pointing it to http://hanselmanblog.azurewebsites.net so I need to add it BACK not strip it. Per https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/proxy-load-balancer?view=aspnetcore-2.2#deal-with-path-base-and-proxies-that-change-the-request-path
|
@shanselman / @Tratcher - if this isn't resolved, would it make sense for the two of you to discuss this on a call briefly? Just suggesting 😄 |
We've chatted and I've redirected him to #5898. There's several related scenarios we can address together. |
Great! |
For me it worked for almost everything, but when an unlogged user tries to access an page with the
but during the navigation, the user gets http://server/basepath/basepath/Account/Login Anyone have this issue? Is it a bug or configuration? |
Can confirm I'm experiencing the same issue using FrontDoor --> WebApp --> Logout Auth. The internal logout mechanics seem to be ignoring the usePathBase logic to build downstream routing. |
@SheepRock can you show your full middleware ordering in Startup.Configure? Changing PathBase after |
The weird thing is that it works on my dev computer, but when I deploy to the Windows Server 2008 R2 server it fails. Currently I'm using Also, it looks like ForwardedHeaders aren't working, since |
In 2.2 there was an issue with KnownProxies where it didn't match because RemoteIpAddress was in an IPv6 format. Make sure the formats match. This has been fixed in 3.0. Please open a new issue for your LoginPath problem so we can investigate that specifically. Closed issues are not assigned for investigation. |
Sorry to use this platform but I need to find another issue and can't find it because GitHub won't let me find issues I'm subscribed to.
I'm hosting an ASP.NET Core application on Linux with Apache web server behind a reverse proxy as recommended. I can setup my environment to only proxy a subdirectory of the domain to the app, but the app doesn't know that because the proxy translates the public subdirectory to the internal root directory. Now there was some discussion going on here about whether to let the hosting configure this (just like the port number of Kestrel web server through an environment variable) and how an application can handle it through code until then.
I need to find that code. I'm sure it was mentioned here, but neither Google nor GitHub won't find it for me. And of course I'm not archiving GitHub notification e-mails that long. Maybe I should do that. Can you please point me to the issue for that?
The text was updated successfully, but these errors were encountered: