mod_rewriteとFolloSymlinks

  • mod_rewrite は FollowSymLinksと一緒に
    • FollowSymLinks 有効になってないと403 HTTP_FORBIDDEN
// ap_hook_fixups
// (応答内容の生成を変更するラスト・チャンス)

    /*
     *  Do the Options check after engine check, so
     *  the user is able to explicitely turn RewriteEngine Off.
     */
    if (!(ap_allow_options(r) & (OPT_SYM_LINKS | OPT_SYM_OWNER))) {
        /* FollowSymLinks is mandatory! */
        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
                     "Options FollowSymLinks or SymLinksIfOwnerMatch is off "
                     "which implies that RewriteRule directive is forbidden: "
                     "%s", r->filename);
        return HTTP_FORBIDDEN;
    }
  • ap_hook_fixups ... コンテンツハンドラが起動する直前
// http://kaigai.sblo.jp/archives/200806-1.html

static void selinux_register_hooks(apr_pool_t *p)
{
    ap_hook_fixups(selinux_setexeccon, NULL, NULL, APR_HOOK_MIDDLE);
}
//fixupというのは、HTTP-BASIC認証やらその他諸々が終わり、コンテンツハンドラが起動される直前に呼び出されるフックとの事。
//ここでは setexeccon() を呼び出すことで、CGIを実行した際のセキュリティコンテキストを設定する事にする。

main -> subrequest
内部リダイレクト => http:// => file://



//http://www.net-newbie.com/trans/mod_rewrite.html#RewriteEngine

mod_rewrite は以下の 2 つのフックを使います:
HTTP リクエストが 読まれた後でかつすべての認証が開始される前に使われる URL-to-filename 変換フック、
そして、認証フェーズの後でディレクトリ毎の設定ファイル (.htaccess) が読まれたが、まだ content ハンドラが 有効になる前に起動される fixup フックです。
注意:ディレクトリ単位の設定ファイル における書き換えエンジンを有効にする場合、これらのファイルに ``RewriteEngine On'' をセットし、かつ ``Options FollowSymLinks'' を有効に しなければなりません。
あなたのところの管理者がユーザの ディレクトリの FollowSymLinks をオーバーライド を禁止していた場合、書き換えエンジンを使うことはできません。 この制限が必要なのは、セキュリティ関連の理由によります。




http://www.maxi-pedia.com/FollowSymLinks

  • FollowSymLinksがoff
    • /index.htmlのリクエストは
      • /www
      • /www/htdocs
      • /www/htdocs/index.html
    • として解決されるらしい

If FollowSymlinks is NOT set at all, Apache has to issue some extra system calls when looking for a file. For example, if you browse to the /index.html document, Apache would look for that file in your /www, /www/htdocs, and /www/htdocs/index.html. These additional system calls will add to the latency. The system call results are not cached, so they will occur on every request.

// パフォーマンス +FollwSymlinks >> -FollowSymlinks
If you are concerned about performance, then always use Options FollowSymLinks. Options FollowSymlinks permits Apache to follow symbolic links in the manner of most Unix applications which is that Apache does not even need to check to see if the file in question is a symlink or not. Enable FollowSymLinks by default and disable it where necessary case-by-case.

  • FollowSymLinks On => symlinkを辿る => symlinkはOSが勝手に解決してくれる ( lstatする必要ない )
    • /wwwがsymlinkがどうかチェック
    • /www/htdocsがsymlinkがどうかチェック
    • /www/htdocs/index.htmlがsymlinkがどうかチェック
  • というオーバーヘッドが生ずる
  • lstatの結果はキャッシュされない => リクエストごとにオーバーヘッド
//http://sonic64.com/2004-01-09.html

しかし、ファイルやディレクトリーがシンボリックされているかどうかチェックするためにそれぞれのファイルやディレクトリーに対して lstat 関数を実行します。さらに、lstat の結果はキャッシュされないのでリクエストのたびに発生します。
   // FollowSymLinksより先にRewriteEngine On/Offチェックしている
   // FollowSymLinksのOn/Offでmod_rewriteの動作に影響しないようにするため
   // (RewriteEngine On/Offで明示的にスイッチさせる)

    /*
     *  only do something under runtime if the engine is really enabled,
     *  for this directory, else return immediately!
     */
    if (dconf->state == ENGINE_DISABLED) {
        return DECLINED;
    }

    /*
     *  Do the Options check after engine check, so
     *  the user is able to explicitely turn RewriteEngine Off.
     */
    if (!(ap_allow_options(r) & (OPT_SYM_LINKS | OPT_SYM_OWNER))) {
        /* FollowSymLinks is mandatory! */
        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
                     "Options FollowSymLinks or SymLinksIfOwnerMatch is off "
                     "which implies that RewriteRule directive is forbidden: "
                     "%s", r->filename);
        return HTTP_FORBIDDEN;
    }

    /*