2011-03-09 10 views
7

gzipのapache .gzコンテンツ用の単純なコンテンツハンドラを作成する方法を教えてください。解凍してhttp://localhost/doc/FAQ/Linux-FAQ.gzとし、ブラウザにプレーンテキストとして送信します。 Linuxのドキュメントは/ usr/share/docとlocalhost/doc /にたくさんあります。私は、コンテンツを読むためにzless、zcat、またはvimを使用したくありません。私はApacheを使って自分のローカルマシン上のドキュメントを閲覧し、Webブラウザに標準のテキストとしてそれを復活させ、毎回* .gzファイルをダウンロードするように要求しないようにします。apache .gz Linuxドキュメントのgzipコンテンツハンドラ/ usr/share/docとlocalhost/doc/

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の内容を処理できますか?

ブラウジングのドキュメントがずっと簡単になります。ここで助けてくれるプログラムのリソースはすばらしいでしょう。

答えて

7

私は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 installコマンドが追加されました。ここに私の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とあなたが得る結果何を参照してください。

+0

@dolan上記のセクションにセクションを置くことができますか? – nelaaro

+0

@nelaar知っている限り、それはうまくいくはずです。あなたのコードを含めるように投稿を更新しました。正常に動作しない場合に返信する –

+0

/etc/apache2/sites-enabled/000-default: の41行目に構文エラーがあります。無効なコマンド 'ヘッダー'が間違っているか、サーバ設定に含まれていないモジュールで間違っていると定義されています 41ヘッダセットContent-Encoding:gzip – nelaaro

0
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 
+0

私は私のコメントを外しました。それでも私に問題があります – nelaaro

+0

私にとっては、 'AddType'で始まる行をコメントアウトした後で動作します。 – ggg

関連する問題