简体   繁体   English

Iis反向代理404

[英]Iis reverse Proxy 404

We have an api made from .net core deployed on a server with a reverse proxy configured in iis.我们有一个由 .net 核心制成的 api 部署在服务器上,并在 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.当我们从 swagger 或直接使用 ip 地址(例如 10.18.0.1/api/Call)测试 api 时,它工作正常。 However, once we used the reverse proxy, like https://mywebsite.com/api/Call , it returns a 404 Not Found error.但是,一旦我们使用反向代理,例如https://mywebsite.com/api/Call ,它就会返回 404 Not Found 错误。

There is an implemented Basic Auth for the endpoint with accepts GET, POST, and PUT method.端点实现了基本身份验证,接受 GET、POST 和 PUT 方法。 If I try to call the same url with DELETE method, it does return 401.如果我尝试使用 DELETE 方法调用相同的 url,它会返回 401。

I am really not a DevOps nor am I knowledgable in this so a little help would really be appreciated.我真的不是 DevOps,我也不是这方面的知识渊博,所以非常感谢您的帮助。

=========================================================================== 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.这是一个长期存在的规则,以前可以正常工作,但是,当将新规则添加到 web.config 时,就会发生错误。 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.删除操作 url 的 /Profile 之后的最后一个“/”后,此问题已得到修复。 The url was being called like this "http://myapp.com/api/User/Profile/Addess/1", "http://myapp.com/api/User/Profile/123" etc. url 被称为“http://myapp.com/api/User/Profile/Addess/1”、“http://myapp.com/api/User/Profile/123”等。

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.我的预感是匹配 url 的原因,因为它没有“/”,但我不确定。 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 :这是因为如果您按照 URL 重写, {R:1}将是/Address/1

在此处输入图像描述

And the URL you rewrite is:而你重写的 URL 是:

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

So the final rewritten URL will look like this:所以最终改写的 URL 将如下所示:

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

This will result in an extra "/" in the URL.这将导致 URL 中出现额外的“/”。

solution:解决方案:

solution 1: Modify match URL:解决方案1:修改匹配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:解决方案2:修改动作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.以上两种方案都可以解决这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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