• ベストアンサー

2台のサーバで違うサービス

現在,ルータに2台のサーバが接続されています.サーバAはウェブサーバとして正常に動作しています. 今回,サーバBを増設し,違うサービスを行いたいのですが,どのような設定を行うとよろしいでしょうか. ルータ |-サーバA(192.168.0.2) http://example.com/ |-サーバB(192.168.0.4) http://a.example.com/ httpd.confのvirtual hostに設定を行うと思うのですが,設定方法又は,同じような条件の設定方法が示されたページを教えてください. 一応,サーバAに設定した内容は以下の通りです. この設定では上手く接続されませんでした.具体的には,virtual hostに設定されていない*.example.comはexample.comにリダイレクトされるように設定していますので,example.comに飛ばされてしまいます. <VirtualHost 192.168.0.4> ServerAdmin webmaster@example.com DocumentRoot /var/www ServerName a.example.com </VirtualHost> どうか,よろしくお願いいたします.

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

  • ベストアンサー
回答No.2

#1です。 補足拝見しました。 まずはvirtualhostの設定で上手くいってよかったですね^^ >実験的に,サーバAに次のようなvirtualhostを設定すると,上手くいきました. >しかし,192.168.0.4では,内部からしかアクセスできないと思います. ということですが、実際に設定されているアドレスもローカルアドレスで、ルータのバーチャルサーバ(ルータによってはIPマスカレードとかポートマッピングなど)で外部へ公開されているのでしょうか。 その場合は192.168.0.4もあわせて外部へ公開すれば、外からもアクセスできると思います。(もちろん外部からの1次アクセスは192.168.0.2へ着ますが、192.168.0.4も公開しておかないとアクセスできなくなってしまいます) 逆にグローバルアドレスを取得しているのであれば、内部にDNSを立てておいたほうが何かと融通が利きます。今回のサービスの振り分けでも有効ですし、サーバを乗せ替えたりするような場合でもキャッシュタイムを短くしておいてスムーズに移行することが出来ます。 参考にしてください。

hyd155
質問者

お礼

少し方向が変わってしまったにも関わらず,丁寧に解説していただき,ありがとうございました. 今度は,DNSサーバを立てて試してみることに致しました. 本当にありがとうございました.

hyd155
質問者

補足

何度もありがとうございます. 現在,ルータのポートマッピングでサーバAを公開しています. つまり,example.com:80への接続はサーバAに送られることになります.ここで,前述のようにa.example.com:80への接続を192.168.0.4(サーバB)に送るための方法として, > 192.168.0.4もあわせて外部へ公開すれば とは,違うポート番号で・・ということでよろしかったでしょうか. 例えば,サーバBは8080番で公開とか・・? ルータへの設定は8080番をサーバBにポートマッピング,サーバBでのhttpd.confの設定ではServerName/Listenともに8080番に設定,サーバAではvirtualhostに次のような設定をしてみると良いのでしょうか. <virtualhost 192.168.0.2> ServerName a.example.com Redirect / http://example.com:8080/ </VirtualHost> どうも,的外れなことを言っているような気がするのですが・・ 申し訳ありませんが,もう少し詳しく教えていただいてもよろしかったでしょうか.

全文を見る
すると、全ての回答が全文表示されます。

その他の回答 (2)

  • gsx_rider
  • ベストアンサー率40% (53/130)
回答No.3

<virtualhost 192.168.0.2> ServerName a.example.com Redirect / http://example.com:8080/ </VirtualHost> 以上の設定ですとvirtualhostの設定をせずとも ルーターの192.168.0.4の8080番を公開する事で http://example.com:8080 へのアクセスは可能だと思いますので 本末転倒のように思います virtualhost は本来一つのサーバーの中に複数のドメインを 与えるものですのでこの場合 やはり自ネットワーク内にDNSを設置するか ルーターでは無く ゲートウェイとなるマシンを設置して 細かく設定する方法が適切です 

hyd155
質問者

お礼

ご回答ありがとうございます. > 与えるものですのでこの場合 やはり自ネットワーク内にDNSを設置するか ルーターでは無く ゲートウェイとなるマシンを設置して細かく設定する方法が適切です やはりそうですか・・ まだまだ技術が足りないのだという理由で,DNSからは逃げておりましたが,本格的に取り組まなくてはならないようですね・・ 頑張って取り組んでみることにします. 本当にありがとうございました.

全文を見る
すると、全ての回答が全文表示されます。
回答No.1

>httpd.confのvirtual hostに設定を行うと思うのですが,設定方法又は,同じような条件の設定方法が示されたページを教えてください. サービスの割り当てはhttpd.confではなく、DNSのゾーンファイルで行います。質問者様のDNSはサーバAで動いているのでしょうか。 それとも外部のDNSで動いているのでしょうか。 具体的にはexample.comのゾーンファイルの中で example.com. IN A 192.168.0.2 a.example.com. IN A 192.168.0.4 と指定してあげれば、振り分けることが出来ます。 質問者様がやろうとしていたVirtualHostの設定は、サーバAの中に 192.168.0.4を内包しているばあいに設定する方法です。 参考にしてください。

hyd155
質問者

補足

ご回答ありがとうございます. DNSは内部には立てていません. やっぱり,立てたほうが簡単に設定できるのでしょうか・・ 本日,色々調べていたところ,virtualhostのredirectを使用することで,私の望んでいることが実現できそうなのです. 具体的には,(質問として書いた内容とは若干変わっているかもしれませんが) a.example.comとしてアクセスしてきたものをサーバBにリダイレクトしたいと思います. 実験的に,サーバAに次のようなvirtualhostを設定すると,上手くいきました. <virtualhost 192.168.0.2>    ServerName a.example.com    Redirect / http://192.168.0.4/ </VirtualHost> しかし,192.168.0.4では,内部からしかアクセスできないと思います. これを外部からアクセスできる形で設定したのですが,このようなことは可能でしょうか.

全文を見る
すると、全ての回答が全文表示されます。

関連するQ&A

  • 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 をちゃんと書いています。

  • VirtualHostの設定

    名前ベースのVirtualHostの設定を試してるのですが、 Permission denied: file permissions deny server accessとなり アクセスできません。wwwはアクセスできます。 サイトでいろいろ調べているのですが、解決できませんでした。 パーミッションも777に設定しています。httpd.confの設定を載せます。pperというユーザーを追加しました。 *ホストとドメインは仮名 NameVirtualHost *:80 <VirtualHost *:80> ServerAdmin webmaster@dummy-host.example.com DocumentRoot /var/www/html ServerName www.pani.mydns.jp ErrorLog logs/www.pani.mydns.jp-error_log CustomLog logs/www.pani.mydns.jp-access_log common </VirtualHost> <VirtualHost *:80> ServerAdmin webmaster@dummy-host.example.com DocumentRoot /home/pper/html ServerName test.pani.mydns.jp ErrorLog logs/test.pani.mydns.jp-error_log CustomLog logs/test.pani.mydns.jp-access_log common </VirtualHost>

  • パーパーフェクトPHP[技術評論社]のP29まで終

    パーフェクトPHP[技術評論社]のP29まで終わりました。 次に、P30に入りました。そこで! 以下教本の中身です。 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  ■バーチャルホストの追加手順  バーチャルホストを追加する際はまずドキュメントルートとなるデレクトリを作成します。 C:\xampp\apache\conf\extra\httpd-vhosts.confにバーチャルホストの設定を追加します。 <VirtualHost>で囲まれた部分をコピーして、ServerNameやDocumentRootの値を書き かえて保存した後、Apacheを再起動します。また、必要に合わせて C:\Windows\System32\drivrs\etc\hostsにドメインの指定を追加します。  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  以上ですが、  「<VirtualHost>で囲まれた部分をコピーして、ServerNameやDocumentRootの値を書き かえて保存します」  とありますが! 「※何をやるのか!意味がまったく分かりません!?」  以下が、C:\xampp\apache\conf\extra\httpd-vhosts.conf  のファイルの中身の 「ServerNameやDocumentRootの値を書き かえ」は  教本・パーフェクトPHP P28の「ドキュメントルートの設定」 で、既に終了しているのでは!ないでしょうか!? 素人の考えですが、「※間違いでしょうか」  ・・\httpd-vhosts.confの  ファイルの現在のプログラムの中身です。宜しくお願いします。 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  # Virtual Hosts # # Required modules: mod_log_config # 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.4/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 *:80> ServerName study.localhost DocumentRoot "C:/xampp/htdocs/study.localhost" DirectoryIndex index.php index.html <Directory "C:/xampp/htdocs/study.localhost"> AllowOverride All Allow from All </Directory> </VirtualHost> ##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> ##ServerAdmin webmaster@dummy-host.example.com ##DocumentRoot "C:/xampp/htdocs/dummy-host.example.com" ##ServerName dummy-host.example.com ##ServerAlias www.dummy-host.example.com ##ErrorLog "logs/dummy-host.example.com-error.log" ##CustomLog "logs/dummy-host.example.com-access.log" common ##</VirtualHost> ##<VirtualHost *:80> ##ServerAdmin webmaster@dummy-host2.example.com ##DocumentRoot "C:/xampp/htdocs/dummy-host2.example.com" ##ServerName dummy-host2.example.com ##ErrorLog "logs/dummy-host2.example.com-error.log" ##CustomLog "logs/dummy-host2.example.com-access.log" common ##</VirtualHost>

    • ベストアンサー
    • PHP
  • /etc/httpd/conf/httpd.confの中身について

    失礼します。linux初心者です。 Apacheの仮想サイトの構成について調べたいのですが、 /etc/httpd/conf/httpd.confを参照したところ以下の様に記述されています。 <VirtualHost *:80> # ServerAdmin webmaster@dummy-host.example.com # DocumentRoot /www/docs/dummy-host.example.com # ServerName dummy-host.example.com # ErrorLog logs/dummy-host.example.com-error_log # CustomLog logs/dummy-host.example.com-access_log common #</VirtualHost> これは、 WEB接続使用ポート:80 サーバードメイン:webmaster@dummy-host.example.com ルートディレクトリ:/www/docs/dummy-host.example.com サーバー名:dummy-host.example.com ログ保存場所:dummy-host.example.com-error_log        logs/dummy-host.example.com-access_log common という解釈で間違いありませんでしょうか。 またこの仮想サイトのsmarty保存場所を調べるにはどのようにすればよいですか。

  • PHPの教本の説明などで質問があります。

    http://www.amazon.co.jp/dp/4774144371  以上教本の、P28~P29の質問です。  以下中身です。 ■ドキュメントの設定 ドキュメントルールをC:\xampp\htdocs\study.localhostに設定します。まずはディレクトリを作成します。  次にApacheのバーチャルホストを設定します。C:\xampp\apache\conf\conf\extra\http-vhost.conf を開き次の設定を追加してください。<VirtualHost>で囲まれた部分がバーチャルホストの設定です。ServerNameにWeb ブラウザからアクセスする際のドメイン名(study.localhost)、DocumentRootおよび<Directory>にドキュメントルートへの パスを指定します。 (パソコン側のファイルを以下のプログラムに修正しろと言うことでしょう!?)  NameVirtualHost *:80 <Virtualhost *80> ServerName study.localhost DocumentRoot C:\xampp\htdocs\study.localhost DirectoryIndex index.php index.html <Directory “C:\xampp\htdocs\study.localhost”> AllowOverride All Allow from All </Directory> </VirtualHost> ---------------------------------------------------------- 以上が教本の中身です。 そこで質問があります! 第一の質問  教本では C:\xampp\apache\conf\conf\extra\http-vhost.confですが! パソコン側に存在するファイルは httpd-vhosts.confです。 教本のhttp-vhost.confではなくて、httpの部分がパソコン側では httpdと成っていて、dが多いです! ファイル名が違うことで、設定後何か支障はありますか!? 第二の質問  以下が、httpd-vhosts.conf  ファイルのプログラム全文を以下表示しましたが、 ##NameVirtualHost *:80が二個存在していて、どちらのプログラムを 修正すればいいのでしょうか!?  以上二件よろしくお願いします。 # Virtual Hosts # # Required modules: mod_log_config # 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.4/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> ##ServerAdmin webmaster@dummy-host.example.com ##DocumentRoot "C:/xampp/htdocs/dummy-host.example.com" ##ServerName dummy-host.example.com ##ServerAlias www.dummy-host.example.com ##ErrorLog "logs/dummy-host.example.com-error.log" ##CustomLog "logs/dummy-host.example.com-access.log" common ##</VirtualHost> ##<VirtualHost *:80> ##ServerAdmin webmaster@dummy-host2.example.com ##DocumentRoot "C:/xampp/htdocs/dummy-host2.example.com" ##ServerName dummy-host2.example.com ##ErrorLog "logs/dummy-host2.example.com-error.log" ##CustomLog "logs/dummy-host2.example.com-access.log" common ##</VirtualHost>

    • 締切済み
    • PHP
  • 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> *************************************************** のようなルールになっているのですが、 これをワイルドカード使ってできないでしょうか? 宜しくお願いします!

  • 〆た質問にリンクを張り、仕切り直しの質問です。

    http://okwave.jp/qa/q8351280.html  のご回答等・・でお世話になっております^^ 私なりに頭の中で”紆余曲折”した、質問でした。    私みたいなPHP二年生ですが、  なんでもそうだと思うのですが! “素人というのは”とんでもない勘違いを良くしています! 私もその一人です。  なので、自分だけの考えだけで、事を進められないので苦労しています。   ご回答を下さった、 “「#」が先頭についているのは全部コメントです。” 意味が分かりました^^  現在のプログラムの設定を、とりあえず以下の設定にしました。 教本には「http-vhosts.confファイルを開き追加してください。」  とありましたので追加しましが、間違いないでしょうか!?    まだどこか勘違いをしているような気がします。  ※ 以上URLから何か、新たにどこかのフォルダ内にファイルを追加する!    との、回答の内容と、受け止められました。等・完璧ではございません    !勘違いなのでしょうか!?等・・   何か全体的に大きな勘違いをしているようでしたらご教授をよろしくお願い致します。 # Virtual Hosts # # Required modules: mod_log_config # 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.4/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 *:80> ServerName study.localhost DocumentRoot "C:/xampp/htdocs/study.localhost" DirectoryIndex index.php index.html <Directory "C:/xampp/htdocs/study.localhost"> AllowOverride All Allow from All </Directory> </VirtualHost> ##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> ##ServerAdmin webmaster@dummy-host.example.com ##DocumentRoot "C:/xampp/htdocs/dummy-host.example.com" ##ServerName dummy-host.example.com ##ServerAlias www.dummy-host.example.com ##ErrorLog "logs/dummy-host.example.com-error.log" ##CustomLog "logs/dummy-host.example.com-access.log" common ##</VirtualHost> ##<VirtualHost *:80> ##ServerAdmin webmaster@dummy-host2.example.com ##DocumentRoot "C:/xampp/htdocs/dummy-host2.example.com" ##ServerName dummy-host2.example.com ##ErrorLog "logs/dummy-host2.example.com-error.log" ##CustomLog "logs/dummy-host2.example.com-access.log" common ##</VirtualHost>

    • ベストアンサー
    • PHP
  • バーチャルホストで、同じページをSSLとNon-SSLでアクセスできるようにしたい

    VPSでレンタルサーバをかりています。 (仮想のroot権限を持っています) で、バーチャルホストを以下のようにしています。 ====================================== NameVirtualHost xxx.xxx.xx.xx <VirtualHost xxx.xxx.xx.xx> <Directory /var/www/example.com/htdocs> Options FollowSymLinks AllowOverride All Order allow,deny Allow from all </Directory> ServerAdmin webmaster@example.com DocumentRoot /var/www/example.com/htdocs ServerName example.com ErrorLog /var/log/example.com-error_log CustomLog /var/log/example.com-access_log common </VirtualHost> <VirtualHost xxx.xxx.xx.xx> <Directory /var/www/www.example.com/htdocs> Options FollowSymLinks AllowOverride All Order allow,deny Allow from all </Directory> ServerAdmin webmaster@example.com DocumentRoot /var/www/www.example.com/htdocs ServerName www.example.com ErrorLog /var/log/www.example.com-error_log CustomLog /var/log/www.example.com-access_log common </VirtualHost> <VirtualHost xxx.xxx.xx.xx> <Directory /var/www/admin.example.com/htdocs> Options FollowSymLinks AllowOverride All Order allow,deny Allow from all </Directory> ServerAdmin webmaster@example.com DocumentRoot /var/www/admin.example.com/htdocs ServerName admin.example.com ErrorLog /var/log/admin.example.com-error_log CustomLog /var/log/admin.example.com-access_log common </VirtualHost> ====================================== で、 http://example.com/fdsfdshhfdsh http://www.example.com/fdsfdshhfdsh http://admin,example.com/fdsfdshhfdsh にアクセスできるわけですが、 https://example.com/fdkjsjf のようにSSLでアクセスできるようにしたいと思っています。 で、 「DocumentRoot /var/www/example.com/htdocs」はSSLなしの場合と同様にしたいと思います。 (SSL,NON-SSLは、ファイルを共有) こうするには、どうすればいいのでしょうか? どなたか教えていただければ幸いです。

  • apacheのVirtualHostでの振り分けについて(SSL)

    VirtualHostを使って同一サーバーでのSSLの対応または非対応の振り分けをしています。 WinXP Apache 2.0.55 C:\Apache3 Tomcat 4.1 C:\Program Files\Apache Group\Tomcat 4.1 OpenSSL C:\OpenSSL apacheとtomcatは連携させています。 apache httpd.confの最後に以下を追加するとApacheが起動しません。 <VirtualHost localhost:80> ServerAdmin webmaster@dummy-host.example.com DocumentRoot "C:/Apache3/htdocs"   SSLDisable # ServerName dummy-host.example.com # ErrorLog logs/dummy-host.example.com-error_log # CustomLog logs/dummy-host.example.com-access_log common </VirtualHost> SSLDisableを削除すると、問題なく起動しますがhttp,httpsと両方でアクセス出来てしまいます。 何がいけないんでしょうか? 最終的には、デフォルトでSSL不可にしておいてVirtualHostで 指定したディレクトリにSSLを施したいです。

  • バーチャルホスト設定

    何度も投稿して申し訳ありません(汗) ここしか聞くところがなくて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