Linux 文档 /usr/share/doc 和 localhost/doc/ 的 apache .gz gzip 内容处理程序
如何为 apache .gz gzip 内容创建一个简单的内容处理程序。我希望它解压缩 http://localhost/doc/FAQ/Linux-FAQ.gz 并将其以纯文本形式发送到浏览器。 /usr/share/doc 和 localhost/doc/ 中有很多 Linux 的文档。我不想使用 zless、zcat 或 vim 来阅读内容。我使用 apache 浏览本地计算机上的文档,并让我的 Web 浏览器将其恢复为标准文本,这样它就不会每次都要求我下载 *.gz 文件。
Alias /doc/ "/usr/share/doc/"
Alias local.doc "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
但现在我希望 /usr/share/doc/ 下的所有 .gz 文件都以纯文本形式提供。我想我可以使用 cgi-bin 中的 python 脚本非常简单地做到这一点。我正在为这些文件寻找一个不错的内容处理程序。就像 php 文件的处理方式一样,.gz 应该解压缩并发送到浏览器。
<IfModule mod_php5.c>
AddType application/x-httpd-php .php .phtml .php3
AddType application/x-httpd-php-source .phps
</IfModule>
LoadModule php5_module /usr/lib/apache2/modules/libphp5.so
我看到有一个 mod_deflate,这将如何应用。这可以处理 gzip 内容吗?
这将使浏览文档变得更加容易。任何能在这里提供帮助的编程资源都会很好。
How could I create a simple content handler for apache .gz gzip content. I want it to uncompress say http://localhost/doc/FAQ/Linux-FAQ.gz and send it to the browser as plain text. There is a lot of documentation for Linux in /usr/share/doc and localhost/doc/. I don't want to use zless, zcat or vim to read the content. I use apache to browse the documentation on my local machine and have my web browser revive it as standard text so that it does not ask me to download the *.gz file every time.
Alias /doc/ "/usr/share/doc/"
Alias local.doc "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
But Now I want all those .gz file under /usr/share/doc/ to be servered as plain text. I think I could do that very simply with a python script in cgi-bin. I am looking for a nice content handler for those files. Like the way it php files are handled .gz should be uncompressed and sent to the browser.
<IfModule mod_php5.c>
AddType application/x-httpd-php .php .phtml .php3
AddType application/x-httpd-php-source .phps
</IfModule>
LoadModule php5_module /usr/lib/apache2/modules/libphp5.so
I see there is a mod_deflate, how would this apply. Could this handle the gzip content.
It would make browsing documentation so much easier. Any programing resources to help here would be nice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我之前对 js/css 文件使用过类似的东西(我修改了下面的内容以满足您的需求)。将其添加到您的虚拟主机条目:
上面更新以匹配您的代码
在 ubuntu 中确保启用了标头模块
更新 2:意识到缺少“AddEncoding gzip gz”..否则,文件将继续尝试下载。
Update3:添加了 apache 模块 deflate 安装命令。这是我的 deflate.conf:
您可以首先尝试使用其他类型的文件(例如 css 文件)。示例:
将其添加到您的虚拟主机:
测试 http://127.0.0.1/doc/test.css 和 http://127.0.0.1/doc/test.css.gz 并查看你得到什么结果。
I've used something like this before for js/css files (I modified the below to match your needs). Add this to your virtualhost entry:
Updated above to match your code
In ubuntu ensure that Headers module is enabled
Update2: Realized that "AddEncoding gzip gz" was missing.. otherwise, file kept trying to download.
Update3: Added apache module deflate install command. Here's my deflate.conf:
You could first try with some other type of file (e.g. a css file). Example:
Add this to your virtualhost:
Test http://127.0.0.1/doc/test.css and http://127.0.0.1/doc/test.css.gz and see what result you get.