首页 文章

IIS反向代理到Apache

提问于
浏览
1

我有一个heckuva时间让这个工作 . 我按照以下说明进行操作:

http://learn.iis.net/page.aspx/659/reverse-proxy-with-url-rewrite-v2-and-application-request-routing/

作为一个简单的测试,我试图将我的媒体目录(CSS,图像等)中的任何内容的请求代理到单独主机上的同一目录 . 这是配置:

<rewrite>
    <rules>
       <rule name="ReverseProxyInboundRule1" stopProcessing="true">
            <match url="^(media/.*)" />
            <conditions>
                 <add input="{CACHE_URL}" pattern="^(https?)://" />
             </conditions>
             <action type="Rewrite" url="{C:1}://mystatichost/{R:1}" />
        </rule>
     </rules>
 </rewrite>

在我的 Default.master 中我有一个像这样的图像标签:

<img src="/media/img/homepage.jpg" />

但我不断收到该图像请求的404错误 . 文件 /media/img/homepage.jpg 肯定存在于 mystatichost 上 . 我错过了什么/误解了什么?

1 回答

  • 0

    在我看来,你的正则表达式有些奇怪 .

    而不是 <match url="^(media/.*)" /> ,你应该使用 <match url="(media/.*)" /> . 否则,您的匹配仅从URL字符串的开头开始,这永远不会起作用,因为它始终以 http 开头 .

    所以,简而言之,试试这个:

    <rewrite>
      <rules>
       <rule name="ReverseProxyInboundRule1" stopProcessing="true">
            <match url="(media/.*)" />
            <conditions>
                 <add input="{CACHE_URL}" pattern="^(https?)://" />
             </conditions>
             <action type="Rewrite" url="{C:1}://mystatichost/{R:1}" />
        </rule>
      </rules>
    </rewrite>
    

    如果这不起作用,您对mystatichost的所有请求都需要HTTPS吗?

    也许您可以删除 <conditions> 部分,然后设置 <action type="Rewrite" url="http://mystatichost/{R:1}" /> .

    祝好运!

相关问题