简体   繁体   中英

IIS reverse proxy not working in Azure Web App

I want to use a reverse proxy to point one of my endpoints to a resource that's hosted elsewhere. My primary server (where everything else is hosted) is in an Azure Web App and is otherwise working perfectly.

I've been using this seemingly failproof article along with the other links mentioned at the bottom of it: https://blogs.msdn.microsoft.com/zhiliang_xus_blog/2016/01/19/build-a-google-reverse-proxy-site-on-azure-web-app-in-less-than-3-minutes/

As a baseline, I used a Web App with no additional code and confirmed that the reverse proxy works. This was done by manually creating/editing the web.config file and applicationHost.xdt file then restarting the server.

I've tried 3 separate approaches (all on clean, new web apps) all of which are failing for me:

  1. Push my code, confirm it works, then follow the reverse proxy steps manually
  2. Follow the steps manually, confirm reverse proxy works, then push my code
  3. Put the reverse proxy files into my codebase and push everything at the same time

None of these 3 approaches are working. Is this a bug in Azure? How can I try to figure this out?

The link/way you posted used URL Rewrite to implement a reverse proxy. I tested it and it worked fine with my empty web application. After published a web application to the Azure Web App(For example, an ASP.NET MVC web application), the URL Rewrite stopped working. The reason is that all the requests to your web application are routed by ASP.NET route module.

To enable URL Rewrite for some URLs, we need to disable ASP.NET route for these URLs. For example, if you want to rewrite all the requests with "product/xxx" format to another site. You could add following code to RouteConfig.cs file.

routes.Ignore("product/{action}");

Post XML Transformation (XDT) , have you restarted the site?

I would suggest you to take a look at this blog from Ruslan :
http://ruslany.net/2014/05/using-azure-web-site-as-a-reverse-proxy/

It talks about using a Site extension. It implements the reverse proxy and it does the XDT transformation for you.

If the above is setup correctly, then there is something wrong with the URL Rewrite rules. I would recommend you to enable Failed Request Tracing and debug this further.

The problem in this specific case was the location of my web.config file.

It needs to be in the root directory of the application which, in my case, was not site\\wwwroot . My code was being generated and copied into site\\wwwroot\\dist . Putting the config file in that directory fixed the problem.

Additionally, there are logs that can be enabled to get some insight as to what's going on: https://docs.microsoft.com/en-us/azure/app-service-web/web-sites-enable-diagnostic-log

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM