ApacheのAllowOverrideの設定について

このQ&Aのポイント
  • ApacheのAllowOverrideの設定について調べています。
  • htdocsにAllowOverrideの設定を行おうとしていますが、どちらを設定すればよいのか迷っています。
  • また、二つの設定の違いについても詳しく教えていただけませんか?
回答を見る
  • ベストアンサー

ApacheのAllowOverrideの設定について

すいません、Apacheでサーバを立てているんですが、 htdocsにAllowOverrideの設定をしようとした所、 ----------------------------------------- <Directory /> Options FollowSymLinks AllowOverride None </Directory> ----------------------------------------- と ----------------------------------------- # This controls which options the .htaccess files in directories can # override. Can also be "All", or any combination of "Options", "FileInfo", # "AuthConfig", and "Limit" # AllowOverride None ----------------------------------------- と二つ設定する所があったんですが、どちらを弄れば良いんでしょうか? また、これらの2つはどちらを設定するかで、何か変わってくるのでしょうか? できれば、その違いも、詳しく教えていただけませんか?

質問者が選んだベストアンサー

  • ベストアンサー
  • anmochi
  • ベストアンサー率65% (1332/2045)
回答No.3

> ちなみに、"AllowOverride"の設定は、 > "UserDir"の所にもありますが、これは、 > (1)は例と同じ、(2)は"UserDir"内の > "AllowOverride"の設定と置き換えた場合、 > 例の(1)、(2)と(a)、(b)、(c)は > 同じ関係になるんでしょうか? 今回は(1)がホスト全体の設定で、(2)がUserDirの設定になるんだね。ええと・・・・。前回の回答中の(a)、(b)、(c)との関連はちょっと説明しづらいな。でもまぁ、恐らく同じと考えて良いだろう。君の中でだいぶイメージができあがりつつあるのではないかと思う。 > またその場合、(1)でどう設定しても、個別で > "htdocs"と"UserDir"の方の"AllowOverride" > を設定すれば、個別で設定した方が > "htdocs"や"UserDir"の方では設定が有効になるという > 事でしょうか? いえ~すざっつらいと。このへんはCSSに良く似ている。より局所的な設定が大局的な設定を上書きするという形だな。

sabada
質問者

お礼

anmochiさん、ありがとうございました。 具体的な例なども交えて教えていただいたので、 大変わかり易く理解する事が出来ました。

その他の回答 (2)

  • anmochi
  • ベストアンサー率65% (1332/2045)
回答No.2

> "htdocs"だけに設定を反映。 「だけ」というのはちょっと語弊があるかな。「"htdocs"以下」となるね。例えば、以下のようなディレクトリ構成を考えてみましょー。 /usr/local/apache/htdocs ←(a) /usr/local/apache/htdocs/contents1 ←(b) /usr/share/contents2 ←(c) ここで、<Directory />内での設定を(1)、<Directory local/apache/htdcos>内での設定を(2)とする。さらに、DocumentRootは/usr/local/apache/htdocsであり、Alias /contents2 /usr/share/contents2という設定がされている(←ここが重要)とする。 HTTPクライアントから見たディレクトリ構成は / ←(a') /contents1 ←(b') /contents2 ←(c') となるね。ここまでは良いかな? c'が分からない場合は、Apacheの「alias」コマンドを参照してくれい。 ・(1)、(2)に両方設定した場合: (c)は(1)の設定が、(a)、(b)は(2)の設定が反映される。 ・(1)だけに設定した場合: (a)、(b)、(c)全てに(1)の設定が反映される。 ・(2)だけに設定した場合: (a)、(b)に(2)の設定が反映される。 ちょっとごちゃごちゃ書きすぎたかも。ゆっくり読み返していただきたい。 > という事は、どちらかだけ設定すればよいという事ですか? そうやね。今後ディレクトリ構成をあれこれいじる気は無いのであれば、どちらかに設定しておけばよい。どちらかと言えば、(2)に設定する方が私のポリシーとしてはお勧めだ。

sabada
質問者

補足

anmochiさん、とてもわかり易く勉強になります。 ちなみに、"AllowOverride"の設定は、 "UserDir"の所にもありますが、これは、 anmochiさんの例えで言いますと、 (1)は例と同じ、(2)は"UserDir"内の"AllowOverride"の設定と置き換えた場合、例の(1)、(2)と(a)、(b)、(c)は同じ関係になるんでしょうか? またその場合、(1)でどう設定しても、個別で"htdocs"と"UserDir"の方の"AllowOverride" を設定すれば、個別で設定した方が "htdocs"や"UserDir"の方では設定が有効になるという事でしょうか?

  • anmochi
  • ベストアンサー率65% (1332/2045)
回答No.1

いやいやいや! ちょっと待ってくれ。 君が書いている2個目のAllowOverrideの前後に 前:<Directory ほにゃほにゃ> 後:</Directory> というのが必ずあるはずだ。探すべし。「ほにゃほにゃ」の部分は/home/httpd/htmlや/var/www/htmlなどになっているはずだ。DocumentRootオプションで設定されている値だ。 <Directory />の中の奴は「サーバ全体の初期値」を設定する。 <Directory ほにゃほにゃ>の中は「ドキュメントルート以下」を意味する。 最初はこの違いは見えにくいと思う。これらの違いは、仮想ディレクトリやユーザーディレクトリを利用する際にはっきりするだろう。 で、htdocsに対して設定を行いたい場合は、君の質問中にある下の方を設定してくれれば良い。

sabada
質問者

補足

anmochiさんレスありがとうございます。 すいません、ご指摘どおり、 前:<Directory local/apache/htdocs> 後:</Directory> というのを見逃してました。 前述の -------------------------------------------------- <Directory /> Options FollowSymLinks AllowOverride None </Directory> の方は、サーバ全体に設定を反映。 -------------------------------------------------- 後述の -------------------------------------------------- <Directory local/apache/htdocs> # This controls which options the .htaccess files in directories can # override. Can also be "All", or any combination of "Options", "FileInfo", # "AuthConfig", and "Limit" # AllowOverride None </Directory> の方は、"htdocs"だけに設定を反映。 -------------------------------------------------- と考えて良いんですね? という事は、どちらかだけ設定すればよいという事ですか?

関連するQ&A

  • .htaccessについて

    宜しくお願い致します。 webサーバで.htaccessを有効にしたいと思っております。しかし、どの様に設定すれば良いのか分かりません。自分なりの予想ですが、apachのhttpd.confを.htaccessで検索したら # This controls which options the .htaccess files in directories can # override. Can also be "All", or any combination of "Options", "FileInfo", # "AuthConfig", and "Limit" # AllowOverride ALL という箇所がみつかりました。 ここの設定を変えれば良さそうな気がするのですが・・・ どなたか教えて下さい。宜しくお願い致します。

  • ローカルhtaccessが有効かどうか確認する

    ローカルでphpを勉強しています。 拡張子なしでも表示させるために、 httpd_confとhtaccessを利用して実現しようとしていますが、 どうも上手くいきません。 httpd_confは、 <Directory /> Options FollowSymLinks   #AllowOverride None AllowOverride All Order allow,deny Deny from all </Directory> <Directory "C:/xampplite/htdocs"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.2/mod/core.html#options # for more information. # Options Indexes FollowSymLinks Includes ExecCGI # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # #AllowOverride None AllowOverride All # # Controls who can get stuff from this server. # Order allow,deny Allow from all </Directory> としています。 htaccessには、 php_value default_charset UTF-8 php_value mbstring.language Japanese php_value mbstring.detect_order SJIS,EUC-JP,JIS,UTF-8,ASCII php_value mbstring.http_input auto php_value mbstring.http_output pass php_value mbstring.internal_encoding UTF-8 php_value mbstring.substitute_character none php_flag mbstring.encoding_translation OFF date.timezone = Asia/Tokyo Options +MultiViews AddType text/html .php AddType application/x-httpd-php .html としています。 実は先日まで、なんなく拡張子無しでファイルにアクセスでき、 開発も普通に行っていました。 ですが、突然、拡張子なしのファイルにアクセスすると、 Object not found! Error 404 がでます。 何らかの設定変更などが気づかずに行われた可能性が高いです、 どうも原因を切り分けことができず、あれもこれも試しましたが元通りの拡張し無しでアクセスが できないままです。 そこで、 まず、htaccessそのものが有効になっているか、機能しているか調べたいと思います。 これはどうすれば分かり易く判定できますでしょうか? htaccesssになにか記述したりすると、有効だと判定したりできますか? または、httpd_conf自体に 問題があるのかもしれません。 でも、どうみても無いようなきがします。 とにかく、htaccessが効いてるかどうかしりたいです。 よろしくお願いします。

    • 締切済み
    • PHP
  • Apacheの.htaccessにおけるルート

    apacheの学習中です。 Apacheで、ユーザーディレクトリを有効にしました。 ユーザーディレクトリ内で、 <a href="/">トップページへ</a> とすると、きちんと各ユーザーディレクトリのトップページへいくことを確認しました。 しかし、.htaccess内で ErrorDocument 404 /error/file_not_found.html とし、エラードキュメントを変更しようとすると、エラーページが正しく表示されませんでした。ログを見ると、以下のようになっていました。 File does not exist: /var/www/error/file_not_found.html どうやら、htaccessにおいてのルートディレクトリ指定が、各ユーザー個別のルートディレクトリになっていないようです。htaccessの/を各ユーザーのルートディレクトリに指定するには、どのように設定すればよいでしょうか? 現在、ユーザーディレクトリは以下のように設定しています。すいません。学習中なので、設定におかしなところがあるかもしれません。 <Directory /home/*/public_html> AllowOverride FileInfo AuthConfig Indexes Limit Options MultiViews FollowSymLinks IncludesNoExec <Limit GET POST OPTIONS> Order allow,deny Allow from all </Limit> <LimitExcept GET POST OPTIONS> Order deny,allow Deny from all </LimitExcept> </Directory> 原因が分かる方がいらっしゃれば、ご指摘くださると嬉しいです。 よろしくお願いいたします。

  • Apache2の設定について。

    Solaris10にてApache2.0.52使っていて、ユーザルート上でCGIの許可をしているのにユーザルート上のCGIにアクセスしようとすると403エラーが発生してしまいます。 CGI-BIN以外の場所でCGIを使おうとする場合はエイリアスも設定しないといけないのでしょうか? 下に設定箇所も載せておきますので、確認よろしくおねがいします。 # Control access to UserDir directories. The following is an example # for a site where these directories are restricted to read-only. <Directory /export/home/*/public_html> AllowOverride None Options IncludesNoExec ExecCGI FollowSymLinks <Limit GET POST OPTIONS> Order deny,allow Allow from 192.168.80.0/24 Deny from all </Limit> <LimitExcept GET POST OPTIONS> Order deny,allow Deny from all </LimitExcept> </Directory>

  • Apache(Ver 2.4.4)の設定のエラー

    おはようござます。 Win VISTAです。 Apache(Ver 2.4.4)の設定をしています。(XAMPP 1.8.3) いろいろと参考書を見ながら、意味もわからずhttpdファイル(C:\xampp\apache\conf\httpd)のセキュリティの設定変更をしていますが、 「Access forbidden! 要求されたディレクトリへのアクセス権限がありません。 インデックスドキュメントが存在しないか、 ディレクトリの読み込みが許可されていません。 サーバーの障害と思われる場合は、ウェブ管理者までご連絡ください。」 というエラーが出て困っています。 セキュリティの設定の変更までは、正常にインストールされているとの確認画面が出ていましたので、この変更のミスが原因としか考えられません。 何とど宜しくお願いします。 ============================================================= httpdファイル(C:\xampp\apache\conf\httpd)の内容(変更後です) <変更前の内容はバックアップをとっていませんのでわかりません・・・・> <Directory /> AllowOverride none Require all denied </Directory> DocumentRoot "C:/xampp/htdocs" <Directory "C:/xampp/htdocs"> ・ ・ ・ # Order allow,deny # Allow from all Order deny,allow Deny from All Allow from localhost 127.0.0.1 # AllowOverride All ・ ・ # Require all granted </Directory> ・ ・ ・ <Directory "C:/xampp/cgi-bin"> AllowOverride None Options None # Order allow,deny # Allow from all Order deny,allow Deny from All Allow from localhost 127.0.0.1 # Require all granted </Directory> ============================================================= (C:\xampp\apache\conf\extra\httpd-xampp)<このファイルは全く書き換えていません。> <Directory "C:/xampp/php"> AllowOverride None Options None Require all denied <Files "php-cgi.exe"> Require all granted </Files> </Directory> ・ ・ ・ <Directory "C:/xampp/cgi-bin"> <FilesMatch "\.php$"> SetHandler cgi-script </FilesMatch> <FilesMatch "\.phps$"> SetHandler None </FilesMatch> </Directory> <Directory "C:/xampp/htdocs/xampp"> <IfModule php5_module> <Files "status.php"> php_admin_flag safe_mode off </Files> </IfModule> AllowOverride AuthConfig </Directory> </Directory> Alias /licenses "C:/xampp/licenses/" <Directory "C:/xampp/licenses"> Options +Indexes <IfModule autoindex_color_module> ・ ・ </IfModule> Require all granted </Directory> =============================================================

    • ベストアンサー
    • PHP
  • Apacheのバーチャルホストの設定について

    OS:Scientific Linux6.2 Apache/2.2.15 Apacheのバーチャルホストの設定について現在勉強しております。 参考にしたサイト:http://scientificsrv.com/apache-virtualhost.shtml 私が今悩んでいるのが、DocumentRootになります。 2つのサイトを以下のディレクトリーに入れています。 ドメイン ディレクトリ aaa.com /home/aaa/html bbb.com /home/bbb/html ここで、参考にしたサイトを元にしますと /etc/httpd/conf.d/virtualhost-aaa.conf ← メインホスト用バーチャルホスト設定ファイル作成 <VirtualHost *:80> ServerName aaa.com DocumentRoot /home/aaa/html </VirtualHost> /etc/httpd/conf.d/virtualhost-bbb.conf ← 追加ホスト用バーチャルホスト設定ファイル作成 <VirtualHost *:80> ServerName bbb.com DocumentRoot /home/bbb/html ErrorLog logs/virtual-error_log CustomLog logs/virtual-access_log combined env=!no_log </VirtualHost> と言うようになります。 ここで、DocumentRootはそれぞれ設定していることになります。 そうするとApacheの設定ファイルのDocumentRootはどのように設定したらいいのでしょうか? デフォルトでは以下のようになっています。 /etc/httpd/conf/httpd.conf  # DocumentRoot: The directory out of which you will serve your # documents. By default, all requests are taken from this directory, but # symbolic links and aliases may be used to point to other locations. # DocumentRoot "/var/www/html" # # This should be changed to whatever you set DocumentRoot to. # <Directory "/var/www/html"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.2/mod/core.html#options # for more information. # Options Indexes FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride None # # Controls who can get stuff from this server. # Order allow,deny Allow from all </Directory> このファイルの設定方法が分かりません。デフォルトのままでは、/var/www/htmlを使用することになっています。バーチャルホストの方で設定しているのでここの設定はしなくていいのでしょうか? また、 # This should be changed to whatever you set DocumentRoot to. # <Directory "/var/www/html"> では、htaccessやCGIの許可の設定などを行いますが、バーチャルホストの場合どこで設定すればいいのでしょうか? 勉強不足なのは重々承知していますが、何卒よろしくお願い致します。

  • apacheで「You don't have permission to access 」

    Nagiosというソフトをインストールしているのですが(Webベースで動く)、 http://localhost/nagios にアクセスすると、「You don't have permission to access /nagios/ on this server.」と出てしまいます。Apacheのhttpd.confは最後の行に、 ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin <Directory "/usr/local/nagios/sbin"> AllowOverride AuthConfig Options ExecCGI Order allow,deny Allow from all </Directory> Alias /nagios /usr/local/nagios/share <Directory "/usr/local/nagios/share"> Options None AllowOverride AuthConfig Order allow,deny Allow from all </Directory> を加えて、以下も加えました。 <Directory /> Options FollowSymLinks AllowOverride Options </Directory> AddHandler cgi-script .cgi 何か原因は考えられるでしょうか?これだけではやはり、情報不足でしょうか?

  • Apacheでのユーザーディレクトリ生成

    現在fedora core4 -Apache- でサーバー構築を勉強中なのですが、どうしても解決できない問題が出ました。それはユーザーディレクトリを生成した後、そのディレクトリにアクセスできないという問題です。 ユーザー[testuser]を追加し、/home/testuser/public_htmlを作成後 /home/testuser/public_html/index.htmlを作成、 httpd.confの設定を <IfModule mod_userdir.c> #UserDir disable UserDir /home/*/public_html/ </IfModule> # # Control access to UserDir directories. The following is an example # for a site where these directories are restricted to read-only. # #<Directory /home/*/public_html> # AllowOverride FileInfo AuthConfig Limit # Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec <Directory /home/*/public_html> AllowOverride All Options IncludesNoExec ExecCGI FollowSymLinks <Limit GET POST OPTIONS> Order allow,deny Allow from all </Limit> <LimitExcept GET POST OPTIONS> Order deny,allow Deny from all </LimitExcept> </Directory> とし、ttp://www.testsrv.net/~testuserにアクセスしたところ、 You don't have permission to access /~user1 on this server. アクセス権が無いとはじかれました。 この場合、アクセスできるようにするにはどのようにすれば良いのでしょうか?

  • Debian sarge apache2

    /var/wwwの下に作成したindex.htmlを置いても、 http://xxx.xxxx.xx.xx/apache2-default/のテスト画面をWEB公開したままです。設定が下記になっているからだと思いますが、通常は、どの設定をどのように直すことになりますか? /etc/apache2/sites-available# cat default ・ ・ ・ ・ ・ ・ ・ DocumentRoot /var/www/ <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all # This directive allows us to have apache2's default start page # in /apache2-default/, but still have / go to the right place RedirectMatch ^/$ /apache2-default/ </Directory> ・ ・ ・ ・ ・ ・ ・

  • httpd.confを添削してください!!(長文)

    こんにちわ いろいろと調べながらhttpd.confを自分の理想の動作を得るたねに設定したつもりです。 添削をお願いします。 /_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ DocumentRoot /var/www/html <Directory /> Options FollowSymLinks AllowOverride All </Directory> <Directory "/var/www/html"> #←home Options FollowSymLinks Includes AllowOverride All Order allow,deny Allow from all </Directory> #.htaccessを許可、cgiは不可、ssiは許可、シンボリックリンク許可 Order~略 <IfModule mod_userdir.c> UserDir public_html </IfModule> <Directory /home/*/public_html> AllowOverride AuthConfig Limit Options +ExecCGI +Includes </Directory> #ユーザー領域では.htaccessで認証、アクセス元などで制御の許可。 それ以外は不可。 homeでcgiが不可ですがここでは許可したいので+を付けた。 <Directory "/var/www/cgi-bin"> AllowOverride All Options ExecCGI Order allow,deny Allow from all AddHandler image .gif .jpg AddHandler text/html .htm .html </Directory> /_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ こんな感じなんですがどこかおかしいでしょうか?