home ホーム search 検索 -  login ログイン  | reload edit datainfo version cmd icon diff delete  | help ヘルプ

技術/Apache/mod_includeメモ

技術/Apache/mod_includeメモ

技術 / Apache / mod_includeメモ
id: 1004 所有者: msakamoto-sf    作成日: 2011-08-08 00:08:37
カテゴリ: Apache 

滅多に使うことが無いけど、使うときも無いでも無いということでメモ。

あんまりApacheのバージョン間で大きな違いはないけど、一応バージョンごとのドキュメントURL:

おまけ:IIS/5.0, 6.0系のSSI

以下、Apache 2.x系での実験。

PHPの出力にSSIを適用する。SSIがフィルタとして使えるようになったのは2.0以降のようなので、1.3系は無理かも。あとIISの場合もASPに同時にSSIを適用できないようなので、同様に無理かも。

httpd.conf:

LoadModule include_module modules/mod_include.so
...
AddType text/html .php .html
AddOutputFilter INCLUDES .php .html

/ssi01/foo.html:

<html>
<head>
<title>foo</title>
</head>
<body>
<?php echo "foobar\n"; ?>
<pre>
<!--#include file="foo.html" -->
</pre>
<pre>
<!--#include virtual="/ssi01/foo.html" -->
</pre>
<pre>
<!--#include file="bar.php" -->
</pre>
<pre>
<!--#include virtual="/ssi01/bar.php" -->
</pre>
<pre>
<!--#printenv -->
</pre>
</body>
</html>

/ssi01/foo.html:

<b>foo</b>

/ssi01/bar.php:

<?php echo "<i>bar</i>\n";

/ssi01/.htaccess:

Options Includes

t01.htmlの実行結果:

<html>
<head>
<title>foo</title>
</head>
<body>
foobar
<pre>
<b>foo</b>
</pre>
<pre>
<b>foo</b>
</pre>
<pre>
<i>bar</i> 
</pre>
<pre>
<i>bar</i> 
</pre>
<pre>
HTTP_HOST=localhost
...
DOCUMENT_NAME=t01.html
</pre>
</body>
</html>

.htaccessにIncludesNOEXECを加えてみる:

Options Includes IncludesNOEXEC

t01.htmlの実行結果:

<html>
<head>
<title>foo</title>
</head>
<body>
foobar
<pre>
[an error occurred while processing this directive]
</pre>
<pre>
[an error occurred while processing this directive]
</pre>
<pre>
[an error occurred while processing this directive]
</pre>
<pre>
[an error occurred while processing this directive]
</pre>
<pre>
HTTP_HOST=localhost
...
DOCUMENT_NAME=t01.html
</pre>
</body>
</html>

ドキュメント上では、IncludesNOEXECではexecコマンドが無効化+includeでtext系MIMEのファイル以外はNG、となるので、foo.htmlのincludeは動くかと思われたが、includeが全滅してしまった。
PHPとかも動いているので、内部的にtext MIME型として処理されなかったのかもしれない。

そこで、
/ssi01/baz.css:

div.id01 { color: red; }

を用意し、t01.htmlに

<!--#include file="baz.css" -->
<!--#include virtual="/ssi01/baz.css" -->

を加えてみたところ、IncludesNOEXECが有効でもHTML上にcssの内容が展開された。これによりtext系MIMEが展開されることを確認できた。逆に言えばPHPなど内部でAddTypeするなどしてMIMEを弄っている場合は上手くincludeできない可能性が高い。


プレーンテキスト形式でダウンロード
現在のバージョン : 1
更新者: msakamoto-sf
更新日: 2011-08-08 00:22:57
md5:3c27d329b6d14c4b15d04f480c8b2fb2
sha1:846726c4215a1cb4b92e3594b9d35bfda8bb4df5
コメント
コメントを投稿するにはログインして下さい。