从存档中提供静态文件

发布于 2024-10-18 05:06:59 字数 82 浏览 1 评论 0原文

apache/nginx 是否有一个模块来提供存档中的静态文件(zip、tgz、tbz ...),以便如果指定位置没有文件,则要求指定存档提供该文件?

Is there a module for apache/nginx to serve static files from archive (zip, tgz, tbz …), so that if there is no file in specified location, then stated archive is asked for that file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

从此见与不见 2024-10-25 05:06:59

我不知道有这样的模块。

如果您自己编写,我建议您看一下 try_files 指令 http://wiki.nginx.org/HttpCoreModule#try_files 并将请求参数传递给脚本,例如 php 文件(请参阅 wiki 页面上以以下结尾的 try_files 行:/index.php ?q=$uri&$args;)。

表现:
这样,您可以使用 php 进行一些安全检查,整理搜索引擎机器人,甚至在解压一些文件后对它们进行内存缓存,但这取决于您的具体请求统计数据/模式。

某些工具或 pear 软件包可能允许您将文件提取到管道(stdout)并避免转储到文件系统,或者在 ramdisk 中进行解包以加快速度。但同样,要使类似的东西可靠,要采取的方法取决于您的文件大小。

I'm not aware of such a module.

If you write your own, I would recommend that you take a look ate the try_files directive http://wiki.nginx.org/HttpCoreModule#try_files and hand the request arguments off to a script, e.g. a php file (see on the wiki page the try_files line ending in: /index.php?q=$uri&$args;).

Performance:
That way you do some security checks with php, sort out search engine bots and maybe even memcache some files after you have them unpacked, but that depends on your specific request statistics/patterns.

Some tools or pear packages might allow you to extract files to pipe (stdout) and avoid dumping to the filesystem or unpacking can happen in a ramdisk to speed things up. But again, the way to go depends on your files sizes in order to make something like that reliable.

海的爱人是光 2024-10-25 05:06:59

对于 .tgz 和 .tbz 的情况,大部分性能损失(尤其是大型存档)应该来自以下事实:您必须从磁盘读取并解压缩所有数据,直到并包括您要求的文件。如果您请求存档中的最后一个文件,那么无论是 CGI 脚本还是网络服务器,仍然需要花费时间读取、解压缩和丢弃所有存档数据才能获取您的文件。

Zip 格式确实允许随机访问。如果您的 CGI 脚本非常简单(可以是 sh 脚本),并且本质上只是使用正确的参数调用“unzip”,那么您从服务器模块中获得的加速量将相当小。

也就是说,如果不存在执行此操作的模块,那就有点疯狂了(但不,我还没有找到一个)。

For the case of .tgz and .tbz, most of the performance loss (esp for large archives) should come from the fact you have to read from disk and uncompressing all data up to and including the file you asked for. If you ask for the last file in the archive, then whether a CGI script or a webserver, something will still have to spend the time reading, uncompressing, and discarding all the archive data just to get to your file.

Zip format does allow for random access. If your CGI script is very simple (can be a sh script), and essentially just calls "unzip" with the right argument, then the amount of speedup you could get from having a server module do it would be rather small.

That said, it's kind of crazy if a module for doing this doesn't exist (but no, I haven't been able to find one).

幻梦 2024-10-25 05:06:59

另一种可能性是使用压缩文件系统,具体取决于文件的类型和分布以及重复数据删除。

优点:

- 与 .zip 文件几乎具有相同的效果(存储方面)

- 不需要对 Web 服务器部分进行任何更改

缺点: -

zip DIR 可能有新的 FS

- 可能在使用的操作系统下不存在(例如 ZFS )

也许还有另一种方法如果你澄清你想要实现的目标。

Another possibility may be using a compressed filesystem, depending on types and distribution of the files also with deduplication.

Pro:

-Has almost the same effect als a .zip file ( Storage wise )

-No change on the Webserver part needed

Cons:

-Possibly new FS for the zip DIR

-Maybe not present under used OS ( e.g. ZFS )

Maybe there's another way if you clarify what you are trying to achieve.

对风讲故事 2024-10-25 05:06:59

您应该看看 SquashFS,它是一个压缩文件系统。

您可以将其视为 tar.gz 存档,主要用于 LiveCD/DVD/USB ISO,但完全适用于您的情况。

这里是一个操作方法。

PS:与其他答案相反,您不需要特定的操作系统来使用 SquashFS,但如果您碰巧运行 Solaris 或 FreeBSD,请选择 ZFS 压缩,太棒了!

You should have a look at SquashFS, it's a compressed filesystem.

You can think of it as a tar.gz archive, used mainly in LiveCD/DVD/USB ISOs but perfectly applicable to your situation.

Here is a HowTo.

PS: Contrary to other answers you don't need a particular OS to use SquashFS but if you happen to run Solaris or FreeBSD go for ZFS compression, it's just great !

煞人兵器 2024-10-25 05:06:59

我怀疑没有,特别是在找不到常规文件时作为后备。也就是说,用一个 CGI 脚本来做这件事相当简单。然而,在负载情况下,性能损失很可能会很明显。

I would suspect that there is not, especially as a fallback when regular files are not found. That said, a CGI script to do it would be fairly simple. The performance loss would most likely be noticeable when under load, however.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文