• 締切済み

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 です これくらいの情報で十分でしょうか?足りなければお叱りください。 よろしくお願いします。

みんなの回答

回答No.1

どこが原因か、直接はわかりませんでしたが、 こちらでは、 ServerName に:80はつけてません。 あと、子ネストもなしで、 <Directory~~は別セクションに書いてます。 <VirtualHost *:80> ServerAdmin hoge@hoge DocumentRoot /home/ユーザーネーム/public_html/ドメイン ServerName ドメイン ErrorLog /var/log/httpd/ドメイン/error_log CustomLog /var/log/httpd/ドメイン/access_log common HostNameLookups double UseCanonicalName off </VirtualHost> こんな感じにしてます。 あと、ドメインを指定しなかったとき、先頭を見る特性があるので、 一番最初のVirtualHostのみ、警告ページ(ドメイン書いてよ!)用の ページにしてます。 毎日、IPダイレクトで意味不明リクエストするBOTがいますんで、 これと、普通のドメイン付http/1.1を分けるため、エラーログなども分離してますね。

shipyuuki
質問者

補足

なるほどです ところでindex.cgiを削除してみたのですが、いまだにindex.cgiが表示されます。そんなファイルはもうどこにも存在しないのに…。キャッシュの可能性も考えましたが、そのCGIに値を入れるとちゃんと実行されるのです。何を表示していて何を実行しているのでしょう…気持ち悪いです。

関連するQ&A

  • 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のバーチャルホストの設定について

    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 VirtualHost でワイルドカード(?)設定

    Apache2.2.3を利用しています。 virtualhost.confに50程度のサブドメインを、 下記のように設定をしています。 *************************************************** <VirtualHost *:80>   ServerName suzuki.example.com   DocumentRoot /var/www/html/suzuki/ </VirtualHost> <VirtualHost *:80>   ServerName sato.example.com   DocumentRoot /var/www/html/sato/ </VirtualHost> <VirtualHost *:80>   ServerName yamada.example.com   DocumentRoot /var/www/html/yamada/ </VirtualHost> ・ ・ ・ *************************************************** つまり *************************************************** <VirtualHost *:80>   ServerName ▲▲▲.example.com   DocumentRoot /var/www/html/▲▲▲/ </VirtualHost> *************************************************** のようなルールになっているのですが、 これをワイルドカード使ってできないでしょうか? 宜しくお願いします!

  • 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> このケースはどのように設定するべきでしょうか。

  • 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でVirtualHostを使うとDirectoryIndexが上手くいかない

    CentOS4.4で、Apache2.0を使っています。 バーチャルホストを使っていて、ドメインによって表示を分けるのはうまくいっています。 以下の抜粋のように設定しています。 http://foofoo.com/cgi-bin/hoge/hage/wiki.cgi http://foofoo.com/hoge/hage/wiki.cgi は問題なく実行できています。 <VirtualHost *:80> ServerAdmin xxxx@yyy.com DocumentRoot /var/www/html ServerName foofoo.com ScriptAlias /hoge/hage/ "/var/www/cgi-bin/hoge/hage/" </VirtualHost> 以下のように設定を変えても、 http://foofoo.com/cgi-bin/hoge/hage/ http://foofoo.com/hoge/hage/ へアクセスしても You don't have permission to access /tech/wiki/ on this server. となってしまいます。 <VirtualHost *:80> ServerAdmin xxxx@yyy.com DocumentRoot /var/www/html ServerName foofoo.com ScriptAlias /hoge/hage/ "/var/www/cgi-bin/hoge/hage/" <Location /hoge/hage/> DirectoryIndex wiki.cgi </Location> </VirtualHost> バーチャルホストを使う場合のDirectoryIndexの設定方法を教えてください。 よろしくお願いいたします。

  • 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 wwwなしからwwwありにアクセス

    先日から触り始めた初心者で、右も左もわからずここに辿り着きました。。。 Red Hat Apache2 で構築しています。 www.AAA.co.jp でアクセスすると http://www.japanese.AAA.comが表示します。 www.AAA.co.kr でアクセスすると http://www.korean.AAA.comが表示します。 AAA.co.jp でアクセスすると http://www.japanese.AAA.comが表示します。 . ここで、AAA.co.kr でアクセスした人を http://www.korean.AAA.comを表示/転送させたいのです。 httpd.confに下記を追加したのですが、http://www.japanese.AAA.comが表示されちゃいます... #www.AAA.co.kr <Virtualhost 192.168.1.100> DocumentRoot /va/www/html/korea ServerAdmin root@localhost servername www.AAA.co.kr DirectoryIndex index.html index.html index.htm.index.shtml </Virtualhost 192.168.1.100> #AAA.co.kr <Virtualhost 192.168.1.100> DocumentRoot /va/www/html/korea ServerAdmin root@localhost servername AAA.co.kr DirectoryIndex index.html index.html index.htm.index.shtml </Virtualhost 192.168.1.100> 宜しくお願いします。

  • ApacheのVirtualHostの設定すると、メイン(?)の設定に影響してしまう

    いつもお世話になっております。 ApacheのVirtualHostの設定をして複数サイトを運営したいと思ったのですが、VirtualHostの設定をしたところ、VirtualHostでないURLの方までドキュメントルートがVirtualHostに設定した方のページが表示されるようになってしまいました。 説明が下手すぎるので、具体的にはieserverというDDNSにて aaaaa.dip.jp bbbbb.dip.jp という二つのサブドメインを取得しまして(ドメインは適当です) httpd.confのSection 2 'Main' server configrationには ServerName aaaaa.dip.jp:80 DocumentRoot "/var/www/html" と記述し、 Section 3: Virtual Hostsには NameVirtualHost *:80 <VirtualHost *:80> ServerName bbbbb.dip.jp DocumentRoot /var/www/sample <Directory "/var/www/sample"> Order allow,deny Allow from all </Directory> </VirtualHost> と記述しています。 これで、 http://aaaaa.dip.jpでアクセスすれば/var/www/htmlの中のindex.htmlが、 http://bbbbb.dip.jpでアクセスすれば/var/www/sampleの中のindex.htmlが 表示されると思ったのですが、 どっちのURLでアクセスしても/var/www/sampleの中のindex.htmlが表示されて しまうのです。 ちなみにVirtualHostの設定をコメントアウトしてからリスタートすると /var/www/htmlの中のindex.htmlが表示されるようになります。 何か設定が足りていないのでしょうか? 調べてもちょうど良い文献が見つからず四苦八苦しております。 原因が推測できれば教えていただけると助かります。

  • CGI

    MacOS10.10のApache2でCGIが動きません。 httpd.confの最後にこう記述してます。 <VirtualHost *:80> DocumentRoot "/Users/ユーザー/Sites/www" ServerName ドメイン <Directory /Users/ユーザー/Sites/www> AllowOverride All Options Indexes MultiViews ExecCGI FollowSymLinks AddType application/x-httpd-cgi .cgi .pl AddHandler cgi-script .pl .cgi DirectoryIndex index.html index.htm index.cgi </Directory> </VirtualHost> 記述は合ってると思うんですが……どこが間違ってるのでしょう?

    • ベストアンサー
    • Mac