Linux 文档 /usr/share/doc 和 localhost/doc/ 的 apache .gz gzip 内容处理程序

发布于 2024-10-21 13:11:08 字数 1093 浏览 3 评论 0原文

如何为 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 技术交流群。

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

发布评论

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

评论(2

后来的我们 2024-10-28 13:11:08

我之前对 js/css 文件使用过类似的东西(我修改了下面的内容以满足您的需求)。将其添加到您的虚拟主机条目:

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

    AddEncoding gzip gz
    <FilesMatch "\.gz$">
      ForceType text/plain
      Header set Content-Encoding: gzip
    </FilesMatch>
</Directory>

上面更新以匹配您的代码

在 ubuntu 中确保启用了标头模块

$ sudo a2enmod headers  
$ sudo a2enmod deflate
$ sudo apache2ctl restart

更新 2:意识到缺少“AddEncoding gzip gz”..否则,文件将继续尝试下载。

Update3:添加了 apache 模块 deflate 安装命令。这是我的 deflate.conf:

<IfModule mod_deflate.c>
      # these are known to be safe with MSIE 6
      AddOutputFilterByType DEFLATE text/html text/plain text/xml

      # everything else may cause problems with MSIE 6
      AddOutputFilterByType DEFLATE text/css
      AddOutputFilterByType DEFLATE application/x-javascript application/javascript application/ecmascript
      AddOutputFilterByType DEFLATE application/rss+xml
</IfModule>

您可以首先尝试使用其他类型的文件(例如 css 文件)。示例:

cd /usr/share/doc
cat ".styles { width: 50px; }" > test.css
gzip -c test.css > test.css.gz

将其添加到您的虚拟主机:

    <FilesMatch "\.css\.gz$">
        ForceType text/css
        Header set Content-Encoding: gzip
    </FilesMatch>

测试 http://127.0.0.1/doc/test.csshttp://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:

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

    AddEncoding gzip gz
    <FilesMatch "\.gz$">
      ForceType text/plain
      Header set Content-Encoding: gzip
    </FilesMatch>
</Directory>

Updated above to match your code

In ubuntu ensure that Headers module is enabled

$ sudo a2enmod headers  
$ sudo a2enmod deflate
$ sudo apache2ctl restart

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:

<IfModule mod_deflate.c>
      # these are known to be safe with MSIE 6
      AddOutputFilterByType DEFLATE text/html text/plain text/xml

      # everything else may cause problems with MSIE 6
      AddOutputFilterByType DEFLATE text/css
      AddOutputFilterByType DEFLATE application/x-javascript application/javascript application/ecmascript
      AddOutputFilterByType DEFLATE application/rss+xml
</IfModule>

You could first try with some other type of file (e.g. a css file). Example:

cd /usr/share/doc
cat ".styles { width: 50px; }" > test.css
gzip -c test.css > test.css.gz

Add this to your virtualhost:

    <FilesMatch "\.css\.gz$">
        ForceType text/css
        Header set Content-Encoding: gzip
    </FilesMatch>

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.

咽泪装欢 2024-10-28 13:11:08
cat /etc/apache2/mods-enabled/mime.conf | head -n 30
<IfModule mod_mime.c>

#
# TypesConfig points to the file containing the list of mappings from
# filename extension to MIME-type.
#
TypesConfig /etc/mime.types

#
# AddType allows you to add to or override the MIME configuration
# file mime.types for specific file types.
#
#AddType application/x-gzip .tgz
#
# AddEncoding allows you to have certain browsers uncompress
# information on the fly. Note: Not all browsers support this.
# Despite the name similarity, the following Add* directives have
# nothing to do with the FancyIndexing customization directives above.
#
AddEncoding x-compress .Z
AddEncoding x-gzip .gz .tgz
AddEncoding x-bzip2 .bz2
#
# If the AddEncoding directives above are commented-out, then you
# probably should define those extensions to indicate media types:
#
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-bzip2 .bz2
cat /etc/apache2/mods-enabled/mime.conf | head -n 30
<IfModule mod_mime.c>

#
# TypesConfig points to the file containing the list of mappings from
# filename extension to MIME-type.
#
TypesConfig /etc/mime.types

#
# AddType allows you to add to or override the MIME configuration
# file mime.types for specific file types.
#
#AddType application/x-gzip .tgz
#
# AddEncoding allows you to have certain browsers uncompress
# information on the fly. Note: Not all browsers support this.
# Despite the name similarity, the following Add* directives have
# nothing to do with the FancyIndexing customization directives above.
#
AddEncoding x-compress .Z
AddEncoding x-gzip .gz .tgz
AddEncoding x-bzip2 .bz2
#
# If the AddEncoding directives above are commented-out, then you
# probably should define those extensions to indicate media types:
#
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-bzip2 .bz2
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文