Apacheのバーチャルホストの設定とDocumentRootの設定方法について

このQ&Aのポイント
  • Apacheのバーチャルホストの設定方法とDocumentRootの設定方法について説明します。
  • バーチャルホストの設定ファイルを作成し、ServerNameとDocumentRootを設定します。
  • バーチャルホストの場合、htaccessやCGIの設定はバーチャルホストの設定ファイルで行います。デフォルトの設定は変更する必要があります。
回答を見る
  • ベストアンサー

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の許可の設定などを行いますが、バーチャルホストの場合どこで設定すればいいのでしょうか? 勉強不足なのは重々承知していますが、何卒よろしくお願い致します。

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

  • ベストアンサー
  • EF_510
  • ベストアンサー率50% (306/604)
回答No.1

>このファイルの設定方法が分かりません。デフォルトのままでは、/var/www/htmlを使用することになっています。バーチャルホストの方で設定しているのでここの設定はしなくていいのでしょうか? バーチャルホストに該当しないアクセスが来たときの値を設定します。 すべてバーチャルホストに該当するのであれば、「最初に記述した方」と同じ値にしておけば良いでしょう。 ><Directory "/var/www/html"> >では、htaccessやCGIの許可の設定などを行いますが、バーチャルホストの場合どこで設定すればいいのでしょうか? <VirtualHost></VirtualHost>の中で記述してください。 <VirtualHost *:80> ServerName aaa.com DocumentRoot /home/aaa/html <Directory "/home/aaa/html"> … </Directory> </VirtualHost>

googleoooo
質問者

お礼

回答ありがとうございます。 丁寧に説明していただいたおかげで良く分かりました。 少しお聞きしたいのですが、今回の場合/var/www/htmlと言うディレクトリは使用していないので /etc/httpd/conf/httpd.conf にある # # This should be changed to whatever you set DocumentRoot to. # <Directory "/var/www/html"> … </Directory> は、消してしまっても問題ないのでしょうか? 度々申し訳ありませんがよろしくお願いします。

その他の回答 (1)

  • EF_510
  • ベストアンサー率50% (306/604)
回答No.2

>は、消してしまっても問題ないのでしょうか? 消す必要が無ければ残しておいてください。 もし消す場合は起動前の構文チェックを忘れずに。

googleoooo
質問者

お礼

回答ありがとうございます。 残しておくことにします。 2回にわたり回答していただきまして、本当にありがとうございました。

関連するQ&A

  • apacheのバーチャルホストの設定について

    XAMPPを一通りインストールして、apacheでバーチャルホストの設定を行っております。 環境:Windows2003server ApacheFriends XAMPP (Basispaket) version 1.7.1 + Apache 2.2.11 固定のグローバルIPアドレスは1つ持っており、仮に111.222.333.444としておきます。 バーチャルホストのドメイン名は2つ設定したいと思っており、 aaa.hogehoge.net bbb.hogehoge.net 他業者のDNSにて111.222.333.444をAレコードの値として、それぞれ割り当てしました。 ちなみに、hogehoge.netのAレコードは別のサーバーを当てています。 そこで、携帯から直接 http://aaa.hogehoge.netとhttp://bbb.hogehoge.net をアクセスしましたら、自社サーバーのC:/xampp/htdocs/にあるindex.htmが表示されました。 一応、名前解決は成功したとして、、、 念のため、Windowsのhostsに 111.222.333.444  aaa.hogehoge.net  bbb.hogehoge.net を追加しました。 apacheのメイン設定-httpd.conf ------------------------------ ServerRoot "C:/xampp/apache" Listen 80 ServerAdmin admin@localhost ServerName localhost:80 DocumentRoot "C:/xampp/htdocs/" ↓バーチャルホストのファイルをインクルード Include conf/extra/httpd-vhosts.conf ----以下、httpd-vhosts.confの中身 ホスト名を2つ設定 NameVirtualHost 111.222.333.444:80 <VirtualHost 111.222.333.444:80> ServerAdmin admin@aaa.hogehoge.net DocumentRoot C:/xampp/htdocs/aaa.hogehoge.net ServerName aaa.hogehoge.net ServerAlias www.aaa.hogehoge.net <Directory "C:/xampp/htdocs/aaa.hogehoge.net"> Options FollowSymLinks Includes ExecCGI AllowOverride None Order allow,deny Allow from all </Directory> </VirtualHost> <VirtualHost 111.222.333.444:80> ServerAdmin admin@bbb.hogehoge.net DocumentRoot C:/xampp/htdocs/bbb.hogehoge.net ServerName bbb.hogehoge.net ServerAlias www.bbb.hogehoge.net <Directory "C:/xampp/htdocs/bbb.hogehoge.net"> Options FollowSymLinks Includes ExecCGI AllowOverride None Order allow,deny Allow from all </Directory> </VirtualHost> 設定後、apacheを再起動して、再度携帯電話からhttp://aaa.hogehoge.netとhttp://bbb.hogehoge.netにアクセスしたのですが、C:/xampp/htdocs/にあるindex.htmが表示されてしまい、C:/xampp/htdocs/aaa.hogehoge.net/index.htm、C:/xampp/htdocs/aaa.hogehoge.net/index.htmが表示されません。それぞれのパーミッション自体は766になっているので、こちらは違うと思うのですが、バーチャルホストの設定が悪いのか何処が悪いのか、何か設定が悪いのか全くわからなくなりました。参考書のマニュアルを見ると、「バーチャルホストを設定すると、メインホストの設定が無効になる」と書いてあったので、それでもメインのホストが表示されてしまうということは、バーチャルホストの設定に問題があるのだと自分なりに察知しております。 どなたか、考えられる原因や心当たりある事がございましたら、ご教授をお願いします。

  • Apacheのバーチャルホストの設定について

    Apacheでvirtualhostの設定をしているのですがうまくいきません。 ホスト:ドキュメントルート v1.hoge.com:/var/www/v1/ v2.hoge.com:/var/www/v2/ v3.hoge.com:/var/www/v3/ です。 設定は <VirtualHost *:80> Servername v1.hoge.com:80 DocumentRoot "/var/www/v1" <Directory "/var/www/v1/"> Options Includes FollowSymLinks ExecCGI </Directory> </VirtualHost> <VirtualHost *:80> Servername v2.hoge.com:80 DocumentRoot "/var/www/v2" <Directory "/var/www/v2/"> Options Includes ExecCGI </Directory> </VirtualHost> <VirtualHost *:80> Servername v3.hoge.com:80 DocumentRoot "/var/www/v3" <Directory "/var/www/v3/"> Options Includes FollowSymLinks </Directory> </VirtualHost> で、三つともv*の部分とOptionsがちがうだけになっています。 http://v1.hoge.com/では普通にアクセスできるのですが、http://v2.hoge.com/とhttp://v3.hoge.com/でアクセスしようとするとなぜか/var/www/v1/foo/index.cgiが表示されます。ただしURLは変わらすhttp://v2.hoge.comのままです。ただしhttp://v2.hoge.com/index.htmlと入力するときちんと表示されます。DirectoryIndexでindex.htmlを指定しても無駄でした。 /v1には/v1/index.htmlと/v1/foo/index.cgi、/v2には/v2/index.html、/v3には/v3/index.htmlだけが入っています。 /etc/hostsとか/etc/hosts.confとか/etc/nsswitch,confなども試しました。DNSは登録してからすでに一か月ほど経過していますのでとっくに浸透していると思いますが、v1を設定した時期とv2,v3を設定した時期は半年ぐらい空いてます。 同様の構成を別のサーバーでも試しましたが、症状は同じでした。まあ両方自分で同じように建てたので同じように間違っているだけかもしれませんが。。。 気持ち悪いのは次の四点です。 1.ドキュメントルートが別のホストになる 2.別のホストのドキュメントルートどころかその下にあるCGIが実行される 3.DirectoryIndexが効かない 4.アクセスがやけに遅い(v1とかは普通の速度) エラーログには何もなし、アクセスログにはhttp://v2.hoge.comにアクセスした記録しかないです。 httpd.confではNameVirtualHost *:80と記述し、DocumentRootはコメントアウトしています。 CentOS 6.5 Apache 2.2.15 です これくらいの情報で十分でしょうか?足りなければお叱りください。 よろしくお願いします。

  • apacheのバーチャルホストの設定方法

    MacOSX Snow Leopardを使っています。 apacheは2.2.11です。 httpd.confで/http/Virtual.confを読み出して設定しています。 Virtual.conf ------- # #VirtualHost.conf # NameVirtualHost *:80 <VirtualHost *:80> ServerName www.xxxxx.com DocumentRoot /http/www.xxxxx.com </VirtualHost> ------- ※www.xxxxx.comは、正しく設定されています。 の設定をし、httpdを再起動したところ、IPアドレスでアクセスしても、ドメインでアクセスしても、httpコード403になってしまいます。 *httpdで起動時、エラーはでません。 *httpd -tはSyntaxOK *httpd -sは   VirtualHost configuration:   wildcard NameVirtualHosts and _default_ servers:   *:80 is a NameVirtualHost    default server www.xxxxx.com (/http/Virtual.conf:11)    port 80 namevhost www.xxxxx.com (/http/Virtual.conf:11)   Syntax OK です。 virtual.confをすべてコメントアウトしたところしっかりアクセスできました。 よろしくお願いします。

  • apacheのバーチャルホスト設定について

    apacheのバーチャルホストを次のように2つ設定しました。 <VirtualHost *:80> ServerAdmin admin@hogehoge.co.jp DocumentRoot /www/hogehoge ServerName hogehoge.co.jp </VirtualHost> <VirtualHost *:80> ServerAdmin admin@umauma.co.jp DocumentRoot /www/umauma ServerName hogehoge.co.jp </VirtualHost> 上記でそれぞれ http://hogehoge.co.jp/ http://umauma.co.jp/ にアクセスできるようになりました。 そこで、それぞれにサブディレクトリ http://hogehoge.co.jp/web1/ http://umauma.co.jp/web2/ を持たせたいのですが次のようにaliasはどのように設定したらいいのでしょうか? ・hogehoge.co.jpに対する設定 (ttp://hogehoge.co.jp/web1/にアクセスできました) Alias /web1 "/www/hogehoge/web1" <Directory "/www/hogehoge/web1"> Options Indexes MultiViews AllowOverride None Order allow,deny Allow from all </Directory> ・umauma.co.jpに対する設定?(これはダメでした) Alias umauma/web2 "/www/umauma/web2" <Directory "/www/umauma/web2"> Options Indexes MultiViews AllowOverride None Order allow,deny Allow from all </Directory> このケースはどのように設定するべきでしょうか。

  • バーチャルホスト設定

    何度も投稿して申し訳ありません(汗) ここしか聞くところがなくてorz バーチャルホストの設定ですが Apacheが正常にインストールをしていていると想定して vi /etc/httpd/conf/httpd.conf の下のところにあるバーチャルホストの設定のコメントを外すと 403となってApacheの画面が見れていた localhostも見えなくなってしまします。 何か間違いがあるのでしょうか?ちなみに外したのは #NameVirtualHost *:80 ↓ NameVirtualHost *:80 #<VirtualHost *:80> # ServerAdmin webmaster@”ドメイン名” # DocumentRoot /home/ftpmaster/localhost/”ドメイン名” # ServerName ”ドメイン名” # ErrorLog logs/error_log #</VirtualHost> ↓ <VirtualHost *:80> ServerAdmin webmaster@”ドメイン名” DocumentRoot /home/ftpmaster/localhost/”ドメイン名” ServerName ”ドメイン名” ErrorLog logs/error_log </VirtualHost> です。 他に設定などがあるようでしたらご指摘していただけると嬉しいです。 使用OS→CentOS5i386

  • Apache2でのバーチャルホストの設定について

    現在、メインのサーバhoge.ddo.jpにてApache2によるWebサーバを構築しています。 今回要望があり、ユーザのHPを別のドメインabc.dip.jpにバーチャルホストを利用して運営することになりました。 そこで質問なのですが、 http://abc.dip.jp/ にアクセスすることでユーザのHPにアクセスできます。しかし、 http://hoge.ddo.jp/~misa/ (misaはabc.dip.jpのHPを利用するユーザ) にアクセスしても同じ結果が得られてしまいます。 これを、 http://hoge.ddo.jp/~misa/ でアクセスした場合には、HPを表示できなくしたいのですが、このように設定することはできるのでしょうか? よろしくお願いします。 設定( /usr/local/etc/apache2/httpd.conf ) DocumentRoot "/usr/local/www/data" ServerName hoge.ddo.jp:80 <Directory /home/*/public_html> AllowOverride FileInfo AuthConfig Limit Indexes Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec ExecCGI <Limit GET POST OPTIONS PROPFIND> Order allow,deny Allow from all </Limit> <LimitExcept GET POST OPTIONS PROPFIND> Order deny,allow Deny from all </LimitExcept> </Directory> NameVirtualHost *:80 <VirtualHost *:80> DocumentRoot /usr/local/www/data ServerName hoge.ddo.jp </VirtualHost> <VirtualHost *:80> DocumentRoot /home/misa/public_html ServerName abc.dip.jp </VirtualHost> 環境 FreeBSD 5.4-Release-p2 Apache 2.0.54

  • ApacheでのVirtual Hostの設定

    RedHatLinux9.0/Apache2.0 動的IPのADSLでhn.orgのDDNSを使い、サーバを立てました。 ドメインを持っているため、それを割り当てようと/etc/httpd/conf/httpd.confでVirtual Hostの設定をしたのですが、外部からドメインで接続しても指定したディレクトリを読みに行ってくれず、ディフォルトの/var/www/htmlのディレクトリが表示されていまいます。 DNS(bind?)をこちらで動かしてないのですが、それが原因なのでしょうか? httpd.confはこのようにしています。 # # Use name-based virtual hosting. # NameVirtualHost 127.0.0.1 # # VirtualHost example: # Almost any Apache directive may go into a VirtualHost container. # The first VirtualHost section is used for requests without a known # server name. # <VirtualHost 127.0.0.1> ServerAdmin admin@自分のドメイン.biz DocumentRoot /home/ff/www/ ServerName www.自分のドメイン.biz ServerAlias 自分のドメイン.biz ErrorLog logs/ff/error_log CustomLog logs/ff/access_log common </VirtualHost> また、NameVirtualHost 127.0.0.1と<VirtualHost 127.0.0.1>を、NameVirtualHost *と<VirtualHost *>に変えるとすべてのアクセスがForbiddenになってしまいます。 ログをみたところ、どういうわけかIE6.0なのにHTTP/1.0で繋がっているみたいなのですが、やはりそれなのでしょうか・・・? すみません。アドバイスよろしくお願いいたします。m(_ _)m

  • apache2.2でのバーチャルホストでの設定

    質問させて頂きます。 apache2.2.21にてweb鯖を立てて、ドメインを取得しDDNSにてテストしています。 test.comというドメインにバーチャルホストにて web1.test.comとweb2.test.comを設定 した場合に、 なぜかtest.comとweb1.test.comが同じ内容が表示されてしまいます。 web2は通常通り表示されます。 詳しい方が居ましたら間違い点を教えて下さい。 httpd-vhostsの内容 # # Virtual Hosts # # If you want to maintain multiple domains/hostnames on your # machine you can setup VirtualHost containers for them. Most configurations # use only name-based virtual hosts so the server doesn't need to worry about # IP addresses. This is indicated by the asterisks in the directives below. # # Please see the documentation at # <URL:http://httpd.apache.org/docs/2.2/vhosts/> # for further details before you try to setup virtual hosts. # # You may use the command line option '-S' to verify your virtual host # configuration. # # Use name-based virtual hosting. # NameVirtualHost *:80 # # VirtualHost example: # Almost any Apache directive may go into a VirtualHost container. # The first VirtualHost section is used for all requests that do not # match a ServerName or ServerAlias in any <VirtualHost> block. # <VirtualHost *:80> DocumentRoot "C:/web/web1" ServerName web1.babayasu.info ErrorLog "logs/web1.localhost-error.log" CustomLog "logs/web1.localhost-access.log" common <Directory "C:/web/web1"> order deny,allow allow from ALL Options Indexes FollowSymLinks ExecCGI IncludesNoExec </Directory> </VirtualHost> <VirtualHost *:80> DocumentRoot "C:/web/web2" ServerName web2.babayasu.info ErrorLog "logs/web1.localhost-error.log" CustomLog "logs/web1.localhost-access.log" common <Directory "C:/web/web2"> order deny,allow allow from ALL </Directory> </VirtualHost>

  • Apache(2.0.63)(name basedなvirtual host)で、<想定していないサブドメ>.example.com に対してそれ専用の設定を。

    Apache(2.0.63)で、name basedなvirtual hostをおこなっているのですが、example.com www.example.com develop.example.com の場合は、 それぞれのvirtual hostごとの設定(DocumentRoot など)がよまれ、【<想定していないサブドメ>.example.com】 の場合は、その場合特有の設定(DocumentRoot など)が読まれるようにしたいのですが、どうすればいいのでしょうか? <VirtualHost _default_:*>ほげほげ</VirtualHost>はIPベースのときにしか意味ないようですし・・・ なお。以下のように、ServerName をかかなければいい、というのをどこかでみかけ、実践したのですが、挙動変わらずです。 <VirtualHost *:80> # ServerName wildcard.example.com DocumentRoot /var/www/wildcard.example.com/htdocs </VirtualHost> DNSのほうは、 www 111.111.11.111 @ (None) 111.111.11.111 * (All Others) 111.111.11.111 develope 111.111.11.111 また、httpd.conf のほうは、 NameVirtualHost *:80 をちゃんと書いています。

  • Apache2.2が再起動できない問題についてです

    --- 前提・実現したいこと バーチャルホスト2つ目から3つ目を追加して、Apacheを再起動させたところ[FAILED]と出力されます。 不思議なのが、設定したバーチャルホストを3つから2つに減らしてApacheサーバを再起動したら動きます。 また、構文に誤りがないか確認しましたが「Syntax OK」と出力されました。 ご教授のほどよろしくお願いします。 ------------------------------------------------------------------------------------------------------------------------- --- 発生している問題・エラーメッセージ エラー・ログはございません。 Apache サーバを再起動した際し、[FAILED] ------------------------------------------------------------------------------------------------------------------------- --- vhostで設定した構文です。 NameVirtualHost *:80 <VirtualHost *:80> DocumentRoot /var/www/html/domain-name ServerName domain-name ServerAlias domain-name ErrorLog /var/log/httpd/domain-name/error_log CustomLog /var/log/httpd/domain-name/access_log combined <Directory "/var/www/html/domain-name"> </Directory> </VirtualHost> <VirtualHost *:80> DocumentRoot /var/www/html/domain-name ServerName domain-name ServerAlias domain-name ErrorLog /var/log/httpd/domain-name/error_log CustomLog /var/log/httpd/domain-name/access_log combined <Directory "/var/www/html/domain-name"> </Directory> </VirtualHost> <VirtualHost *:80> DocumentRoot /var/www/html/domain-name ServerName domain-name ServerAlias domain-name ErrorLog /var/log/httpd/domain-name/error_log CustomLog /var/log/httpd/domain-name/access_log combined <Directory "/var/www/html/domain-name"> </Directory> </VirtualHost>