使用前端控制器和 IIS 提供静态文件的方法?
背景
IIS ISAPI 过滤器将所有请求路由到前端控制器 Java CMS 进行响应。没有物理文件对应于给定的 URL。动机:
- 保护 URL
- 实施 SSL
这是服务静态文件(例如音频和视频)的性能瓶颈。并且,池化的应用程序服务器处理线程被占用来服务响应。
想法
让应用程序服务器填充一个 IIS ISAPI 过滤器或 httpmodule,它可以读取文件,然后提供文件服务。可能使用物理文件路径、内容长度和 MIME 类型填充响应标头。
问题
- 没有让 IIS 直接提供文件服务是错误的设计决策吗?如果是这样,请提供有关在安全性和 SSL 实施方面应注意哪些方面的建议(CMS 处理这两个方面)。
- 如果让 IIS 响应,如何利用 IIS 静态文件缓存?或者说缓存有多大好处?
Background
An IIS ISAPI filter routes all requests to a front controller Java CMS for response. No physical file corresponds to a given URL. Motivations:
- Securing URLs
- Enforcing SSL
This is a performance bottleneck serving static files such as audio and video. And, pooled application server processing threads are occupied serving the response.
Idea
Have the application server populate an IIS ISAPI Filter, or httpmodule, that can read and then serve the file instead. Possibly populate response header(s) with physical file path, content length, and mime-type.
Questions
- Bad design decision not having IIS serve the files directly? If so, suggestions for what to look at in terms of security and SSL enforcement (CMS handles both) .
- If going with having IIS respond, what to do to take advantage of IIS static file caching? Or how much benefit is the cache?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您应该允许 IIS 提供静态文件。您可以让 HttpModule(或您的过滤器)将控制权转移回 IIS - 这意味着可能必须复制安全强制代码。另一种方法是让应用程序服务器将控制权转移回 IIS 来提供文件服务(安全检查当然会在之前进行)。或者最后,正如您所概述的,您的应用程序服务器可以注入响应标头,然后 httpmodule 会读取它们并将控制权传递给 IIS。不确定java,但在.NET中你可以使用 HttpResponse.TransmitFile 方法将控制权传回 IIS - 这应该避免需要使 HttpModule 提供文件。
最后,对于缓存,您始终可以发出缓存标头以响应较低级别(代理或客户端缓存)。如果文件正在更改,那么您可以添加文件依赖项等。
编辑:不确定这是否适合您。创建一个 http 处理程序 (ashx) 并将其标记为 IIS 中所需的 SSL。所有媒体文件都将由该处理程序提供服务。该处理程序将把文件作为查询参数。现在,您可以传递一些文件标识符或加密的部分路径(相对于文件存储的配置基本路径),以便用户看不到实际的文件名或路径。您甚至可以制作将在一段时间后过期的令牌(本质上是附加文件 ID 和时间戳并对其进行加密),以便用户无法使用相同的参数再次请求相同的文件。处理程序的伪代码是
I believe that you should allow IIS to serve the static files. You can have HttpModule (or your filter) transferring the control back to IIS - it means that security enforcement code may have to be replicated. Yet another approach can be to make application server transfer control back to IIS to serve the file (security checking would of course happen before). Or lastly, as outlined by you, your app server can inject response headers and then httpmodule would read them and pass control to IIS. Not sure about java but in .NET you can use HttpResponse.TransmitFile method to pass back control to IIS - this should avoid need to make HttpModule serve file.
Finally, for caching, you can always emit cache headers in response to have down level (proxy or client side caching). If files are changing then you can add file dependency etc.
EDIT: Not sure if this will work for you. Create an http handler (ashx) and marked it as SSL required in IIS. All media files will be served by this handler. The handler would take file to be served as query parameter. Now, you may pass some file identifier or encrypted partial path (relative to configured base path to file store) so that actual file name or paths are not visible to user. You can even make tokens that would expire in some time (essentially, append file id & time-stamp and encrypt it) so that user cannot request same file again using same parameter. Pseudo-code for handler would be
这可能有效:
http://www.helicontech.com/ape/
特别是 x-sendfile 部分。
This may work:
http://www.helicontech.com/ape/
Specifically the x-sendfile piece.