阿帕奇。广州为Linux文件的/ usr /共享/ DOC gzip的内容处理器和本地主机/ DOC / [英] apache .gz gzip content handler for Linux documentation /usr/share/doc and localhost/doc/
问题描述
我怎么能生成Apache的.gz gzip的内容一个简单的内容处理程序。我希望它uncom preSS说的http://本地主机/ doc / FAQ里/ Linux的-FAQ 。广州并将其发送给浏览器为纯文本。有很多关于Linux的文件在/ usr /共享/ doc和本地主机/ DOC /。我不想用zless,ZCAT或VIM阅读的内容。我使用Apache来浏览我的本地计算机上的文档,并有我的网页浏览器恢复它作为标准文本,以便它不要求我每次下载* .gz的文件。
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>
但现在我想在/ usr /共享/ DOC所有这些.GZ文件/被servered为纯文本。我想我能做到这一点很简单,在cgi-bin目录python脚本。我寻找这些文件一个很好的内容处理程序。喜欢的方式是PHP文件的处理。广州应pssed并发送到浏览器uncom $ P $。
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
我看到有一个mod_deflate模块,这将如何适用。难道这处理gzip的内容。
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.
推荐答案
我用这样的事情之前,JS / CSS文件(我修改了以下,以符合您的需求)。添加到您的虚拟主机条目:
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>
以上更新,以符合您code
Updated above to match your code
在Ubuntu的保证头模块启用
In ubuntu ensure that Headers module is enabled
$ sudo a2enmod headers
$ sudo a2enmod deflate
$ sudo apache2ctl restart
UPDATE2:意识到AddEncoding gzip的GZ失踪..否则,文件一直试图下载
Update2: Realized that "AddEncoding gzip gz" was missing.. otherwise, file kept trying to download.
UPDATE3:新增Apache模块紧缩install命令。这里是我的deflate.conf:
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>
您可以先用一些其他类型的文件(例如CSS文件)试试。例如:
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>
http://127.0.0.1/doc/test.css 并的http://127.0.0.1/doc/test.css.gz ,看看有什么结果你得到。
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.
这篇关于阿帕奇。广州为Linux文件的/ usr /共享/ DOC gzip的内容处理器和本地主机/ DOC /的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!