我正在IIS8.5上运行IISNode,无法启用静态文件的客户端缓存。这些文件是在不接触节点的情况下使用IISNode服务的。当文件与IISNode一起使用时,它们包含Cache-Control: no-cache头。
如果我只托管节点,绕过IIS和IISNode,我就会得到头部的Cache-Control:public, max-age=604800。
在某个地方,IIS或IISNode正在设置缓存控制值。在IIS中,我似乎无法更改它,就像我得到Cache-Control:no-cache,public,max-age=604800一样
如何防止将无缓存添加到缓存控制头中?
发布于 2014-08-01 20:36:43
如果其中任何一项工作:
1)在IISNode:app.use(express.static(path.join(__dirname, 'public'), {maxAge: 86400000}));中设置缓存
2)添加新的IIS规则来缓存来自youriisnode.js的所有分配

或
3)
在iisnode中服务静态内容的最佳方法是配置URL重写模块,以便IIS静态文件处理程序处理静态内容的请求,而不是node.js。让IIS静态内容比使用任何node.js机制服务这些文件具有很大的性能优势,这是由于围绕缓存的内核级优化,而不需要侵入JavaScript代码。
创建web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="server.js" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<rule name="LogFile" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^[a-zA-Z0-9_\-]+\.js\.logs\/\d+\.txt$"/>
</rule>
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^server.js\/debug[\/]?" />
</rule>
<rule name="StaticContent">
<action type="Rewrite" url="public{REQUEST_URI}"/>
</rule>
<rule name="DynamicContent">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
</conditions>
<action type="Rewrite" url="server.js"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>这样做的目的如下:
1. requests for logs (/server.js.logs/0.txt, /server.js.logs/1.txt, etc.),
2. debugging requests (/server.js/debug),
3. requests for physical files that exist in the public subdirectory (e.g. request for /styles.css will be handled by the static file handler in IIS rather than your node.js application IFF that file exists at the \public\styles.css location).
对所有其他URL的请求(例如/a/b/c?foo=12)现在将发送到server.js应用程序,并将按照在那里实现的逻辑处理。如果是一个特快应用程序,特快路线将适用。
原始资料来源:https://github.com/tjanczuk/iisnode/issues/160#issuecomment-5606547
https://stackoverflow.com/questions/24787519
复制相似问题