IIS 7 and Above
URL Rewrite Module
IIS Reverse Proxy to ASP.NET Core
Last post Jun 21, 2019 07:48 AM by GTHvidsten
Jun 20, 2019 11:46 AM|GTHvidsten|LINK
I have a local ASP.NET Core site running at https://localhost:44359 (in IIS Express). For local testing I need this to answer to some domains, so I tried setting up a Reverse Proxy in IIS for this and installed "Application Request Routing"
and "Reverse Proxy" (I tried setting up IIS hosting, which causes a whole load of other problems, so lets stick to reverse proxy for now).
First I created a new Website in IIS, pointed it to some folder on my harddrive and added the domain name bindings (and use a wildcard certificate for the domain), finally adding 127.0.0.1 example.com to my hosts file. This works just fine and
I can access the IIS site on https://example.com or https://example.net.
Now I try to add reverse proxy to the site using the following rule in the "URL Rewrite" module:
When I try to access https://example.com I get a HTTP Error 502.3 - Bad Gateway with the message The connection with the server was terminated abnormally. If I try without using SSL Offloading I get another simpler
error page with the message Bad Request - Invalid Hostname.
HTTP Error 502.3 - Bad Gateway
The connection with the server was terminated abnormally
Bad Request - Invalid Hostname
I tried using Failed Request Tracing and the logs can be found here:
I had a hunch this might be because of the ASP.NET Core app using a localhost certificate, and the reverse proxy site using a certificate for the domain, so I tried turning off SSL redirects in the ASP.NET Core app to make it respond to regular HTTP
requests, but I'm unfortunately getting the same errors. (I'm still not 100% convinced it has something to do with certificates, though)
So how can I set up a reverse proxy in IIS to forward request to my ASP.NET Core site?
Jun 21, 2019 07:20 AM|Able|LINK
According to your description,I have download your FRT file and I see 400 error in your request.It shows that The request could not be understood by the server due to malformed syntax. The client should not repeat the request without modifications.
Here is the link :
Then I notice that you just write localhost:44359 in your reverse proxy.I think you should enter the ip address of target server.So proxy server could send request to target server to solve the request.
Here is the link,I hope it could help you.
Jun 21, 2019 07:48 AM|GTHvidsten|LINK
This is for local development, which is why I'm using localhost:44359 in the reverse proxy. I could of course use 127.0.0.1:44359 instead, but that has the exact same meaning as the other one and shouldn't be neccessary.
As for "the client should not repeat the request without modifications" I'm not sure what you're referring to. In the FRT file I can see that requests to example.com gets translates to a request to localhost:44359, which is what I want. Why it doesn't work
is beyond me.
As for the detailed errors, this is already on, and doesn't give any more information than is in the FRT file. When I turn off "SSL Offloading" I don't even get the regular IIS error page, but only the text "Bad Request - Invalid Hostname" as plaintext (no
detailed errors at all, just that text).