简体   繁体   中英

Iis reverse Proxy 404

We have an api made from .net core deployed on a server with a reverse proxy configured in iis.

When we test the api from the swagger or directly using the ip address, say 10.18.0.1/api/Call, it works fine. However, once we used the reverse proxy, like https://mywebsite.com/api/Call , it returns a 404 Not Found error.

There is an implemented Basic Auth for the endpoint with accepts GET, POST, and PUT method. If I try to call the same url with DELETE method, it does return 401.

I am really not a DevOps nor am I knowledgable in this so a little help would really be appreciated.

=========================================================================== UPDATE: Problem was found on the Inbound Rule. The code goes something like this.

<rule name="InBound001" stopProcessing="true">
   <match url="^api/User/Profile(.*)" />
   <action type="Rewrite" url="http://10.18.1.1/api/User/Profile/{R:1}" />
</rule>

This is a long standing rule that was properly working before, however, when the a new rule was added to the web.config the error occurred. Note that new rules have already been added before as well but no error occurred, this only happened recently.

The issue was fixed when the last "/" after /Profile on the action url was removed. The url was being called like this "http://myapp.com/api/User/Profile/Addess/1", "http://myapp.com/api/User/Profile/123" etc.

I'd like to highlight that it was working okay without issue prior to the report of the issue. I would just want to understand why it suddenly not working and was fixed when that "/" was removed. My hunch is cause of the match url, cause it does not have the "/" but I'm not sure. And shouldn't it still match given that (.*) means match whatever comes after?

This is because if you follow your URL Rewrite, {R:1} will be /Address/1 :

在此处输入图像描述

And the URL you rewrite is:

http://10.18.1.1/api/User/Profile/{R:1}

So the final rewritten URL will look like this:

http://10.18.1.1/api/User/Profile//Address/1

This will result in an extra "/" in the URL.

solution:

solution 1: Modify match URL:

<rule name="InBound001" stopProcessing="true">
   <match url="^api/User/Profile/(.*)" />
   <action type="Rewrite" url="http://10.18.1.1/api/User/Profile/{R:1}" />
</rule>

solution 2: Modify action URL:

<rule name="InBound001" stopProcessing="true">
   <match url="^api/User/Profile(.*)" />
   <action type="Rewrite" url="http://10.18.1.1/api/User/Profile{R:1}" />
</rule>

Both of the above solutions can solve this problem.

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