【发布时间】:2021-02-25 01:07:52
【问题描述】:
我目前正在使用 nginx(适用于 Windows)创建以下反向代理,并使用相应的 sub_filter 将 CSS 注入 HTML。我想在 IIS 10 中复制它:
location /files {
proxy_pass http://localhost:999/files;
proxy_set_header Accept-Encoding "";
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
sub_filter
'</head>'
'
<link rel="stylesheet" type="text/css" href="https://github.io/test/CSS/themes/dark.css">
<style>
.CalendarEvent\/downloaded\/2vSrJ {
background: rgba(39, 194, 76, 0.7) !important;
border-left-color: rgba(39, 194, 76, 0.0) !important;
}
</style>
</head>';
sub_filter_once on;
}
我可以使用 IIS URL Rewrite 设置相同的反向代理。但是,我不知道如何将相应的 sub_filter 代码添加到 URL 重写规则中。我猜它可以通过Outbound Rule 来完成;但是,我无法创建正常工作的出站规则。
下面是我在反向代理http://mywebsite.com/files 之外添加出站规则的最佳尝试。不幸的是,我得到的响应是:“500 - 内部服务器错误”。当我访问网页时。
另外,我不确定如何限制此出站规则以将此 CSS 模块仅应用于反向代理:http://mywebsite.com/files。我试图添加一个条件以将其限制为我的反向代理;但显然,我做得不对。我所做的一切都因内部服务器错误消息而破坏了我的多个网站。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpErrors errorMode="Custom" lockAttributes="allowAbsolutePathsWhenDelegated,defaultPath" />
<rewrite>
<rules>
<rule name="Redirect to HTTPS" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
<add input="{REMOTE_ADDR}" pattern="192.168.1.2" negate="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
<rule name="ReverseProxy-FILES" enabled="true" stopProcessing="false">
<match url="files\/?(.*)" />
<action type="Rewrite" url="http://localhost:999/files/{R:1}" />
</rule>
</rules>
<outboundRules rewriteBeforeCache="true">
<rule name="FILES custom CSS" preCondition="IsHTML" enabled="true">
<match filterByTags="None" pattern="</head>" />
<action type="Rewrite" value="<link rel="stylesheet" type="text/css" href="https://github.io/test/CSS/themes/dark.css"></head>" />
<conditions>
<add input="FILES" pattern="files\/?(.*)" />
</conditions>
</rule>
<preConditions>
<preCondition name="IsHTML">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
<defaultDocument>
<files>
<clear />
<add value="index.html" />
<add value="default.aspx" />
<add value="index.htm" />
<add value="Default.htm" />
<add value="Default.asp" />
<add value="iisstart.htm" />
</files>
</defaultDocument>
<staticContent>
<mimeMap fileExtension=".mp4" mimeType="video/mp4" />
<mimeMap fileExtension=".todo" mimeType="text/plain" />
</staticContent>
<directoryBrowse enabled="false" />
</system.webServer>
<system.web>
<compilation debug="true" />
<sessionState mode="InProc" timeout="480" />
</system.web>
</configuration>
PS: In my outbound rule, purposely didn't add the entire CSS until I could get it to work with something a little simpler.
【问题讨论】:
标签: css nginx iis url-rewrite-module