質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
CentOS

CentOSは、主にRed Hat Enterprise Linux(RHEL)をベースにした、フリーのソフトウェアオペレーティングシステムです。

Linux

Linuxは、Unixをベースにして開発されたオペレーティングシステムです。日本では「リナックス」と呼ばれています。 主にWebサーバやDNSサーバ、イントラネットなどのサーバ用OSとして利用されています。 上位500のスーパーコンピュータの90%以上はLinuxを使用しています。 携帯端末用のプラットフォームAndroidは、Linuxカーネル上に構築されています。

Q&A

解決済

1回答

3230閲覧

サブドメインが設定したドキュメントルートと異なる方に向いてしまう

akkkkin

総合スコア83

CentOS

CentOSは、主にRed Hat Enterprise Linux(RHEL)をベースにした、フリーのソフトウェアオペレーティングシステムです。

Linux

Linuxは、Unixをベースにして開発されたオペレーティングシステムです。日本では「リナックス」と呼ばれています。 主にWebサーバやDNSサーバ、イントラネットなどのサーバ用OSとして利用されています。 上位500のスーパーコンピュータの90%以上はLinuxを使用しています。 携帯端末用のプラットフォームAndroidは、Linuxカーネル上に構築されています。

0グッド

0クリップ

投稿2016/12/20 09:31

編集2017/01/15 11:36

掲題の件dえご相談です。

取得したサブドメイン「demo.example.com」が

DocumentRoot /var/www2/htmlのindex.htmlに
向いてしまうのは何故でしょうか?

下記が設定した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" # # Relax access to content within /var/www. # <Directory "/var/www"> AllowOverride None # Allow open access: Require all granted </Directory> <Directory "/var/www2"> AllowOverride All Require all granted </Directory> <VirtualHost *:80> ServerName <IPアドレス> DocumentRoot /var/www2/html </VirtualHost> <VirtualHost *:80> DocumentRoot /var/www/html/hogehoge ServerName hogehoge.com </VirtualHost> <VirtualHost *:80> DocumentRoot /var/www/html/sample ServerName demo.hogehoge.com </VirtualHost> # Further relax access to the default document root: <Directory "/var/www/html"> # or any combination of: ~中略~

追記

■httpd -Sの結果

VirtualHost configuration: *:80 is a NameVirtualHost default server <IPアドレス> (/etc/httpd/conf/httpd.conf:135) port 80 namevhost <IPアドレス> (/etc/httpd/conf/httpd.conf:135) port 80 namevhost hogehoge.com (/etc/httpd/conf/httpd.conf:140) port 80 namevhost demo.hogehoge.com (/etc/httpd/conf/httpd.conf:145) ServerRoot: "/etc/httpd" Main DocumentRoot: "/etc/httpd/htdocs" Main ErrorLog: "/etc/httpd/logs/error_log" Mutex rewrite-map: using_defaults Mutex authdigest-client: using_defaults Mutex proxy: using_defaults Mutex authn-socache: using_defaults Mutex default: dir="/run/httpd/" mechanism=default Mutex mpm-accept: using_defaults Mutex authdigest-opaque: using_defaults Mutex proxy-balancer-shm: using_defaults PidFile: "/run/httpd/httpd.pid" Define: DUMP_VHOSTS Define: DUMP_RUN_CFG User: name="apache" id=48 not_used Group: name="apache" id=48 not_used

■configtestの結果
Syntax OK

■apachectl configtestの結果

*:80 is a NameVirtualHost default server ほげほげ.com (/etc/httpd/conf/httpd.conf:130) port 80 namevhost ほげほげ.com (/etc/httpd/conf/httpd.conf:130) port 80 namevhost ほげほげ2.com (/etc/httpd/conf/httpd.conf:135) *:443 ほげほげ.com (/etc/httpd/conf.d/ssl.conf:56) ServerRoot: "/etc/httpd" Main DocumentRoot: "/var/www/html" Main ErrorLog: "/etc/httpd/logs/error_log" Mutex ssl-stapling: using_defaults Mutex proxy: using_defaults Mutex authn-socache: using_defaults Mutex ssl-cache: using_defaults Mutex default: dir="/run/httpd/" mechanism=default Mutex mpm-accept: using_defaults Mutex authdigest-opaque: using_defaults Mutex proxy-balancer-shm: using_defaults Mutex rewrite-map: using_defaults Mutex authdigest-client: using_defaults PidFile: "/run/httpd/httpd.pid" Define: DUMP_VHOSTS Define: DUMP_RUN_CFG User: name="apache" id=48 Group: name="apache" id=48 ```ご教示いただけますとありがたいです。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

ynakano

2016/12/20 09:34

クライアント側の名前解決は大丈夫?
akkkkin

2016/12/20 09:40

ynakanoさん、いつもありがとうございます。クライアント側の名前解決、というのはどういうことでしょうか?
ynakano

2016/12/20 09:45

クライアントのブラウザのURL欄にどう入力しましたか?ということです。あと、お約束のconfigtestとhttpd -Sは確認済みですか?
A.Ichi

2016/12/20 09:50

ServerName demo.hgehoge.comの名前が違いますが、本物は同じですよね。
ynakano

2016/12/20 09:53

以前のトピックもそうなのですが、なぜこういうtypo(っていうの?)が起こるのでしょうか?ターミナルからコピペできない環境なのでしょうか?
akkkkin

2016/12/20 09:57 編集

A.Ichiさん→同じです。修正しました。ynakanaoさん→テスト忘れておりました。質問に追記しました。
A.Ichi

2016/12/20 10:04

DocumentRootは、複数指定可能でしたっけ?前は1つのみだった様な・・・
akkkkin

2016/12/20 10:05

ターミナルのドメインと例としてこの掲示板に上げているドメインを変えているからです。凡ミスで申し訳ないです。
A.Ichi

2016/12/20 10:09

バーチャルホストが指定されているのですね、失礼いたしました。
Y.H.

2016/12/22 09:10 編集

例示に使用するドメイン(FQDN)は、存在しないことが保証されている example.com, example.jpなどを使用しましょう。(と何度かコメントした記憶が・・・) 実在するドメインを使用されている場合、宣伝と誤認されたり、ドメインの所有者から苦情が寄せられる可能性もあります(この場合適切に対処する覚悟を持って使用されてますか?)。
akkkkin

2016/12/22 09:19

Y.H.様承知しました。修正しました。ご指摘ありがとうございます。
guest

回答1

0

ベストアンサー

CentOS7、Apache 2.4.6でディレクトリ構成とhttpd.confの記載内容・記載順も質問文に合わせて試してみました。
結果再現せず、つまり指定したドメイン名に沿ってコンテンツが出し分けられてます。

・クライアントのブラウザのURL欄に"http://<ipaddr>/"と入力 → /var/www2/html/index.htmlの内容が表示。
・クライアントのブラウザのURL欄に"http://hogehoge.com/"と入力 → /var/www/html/hogehoge/index.htmlの内容が表示。
・クライアントのブラウザのURL欄に"http://demo.hogehoge.com/"と入力 → /var/www/html/sample/index.htmlの内容が表示。

投稿2016/12/20 11:28

ynakano

総合スコア1894

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

akkkkin

2016/12/22 09:04

回答ありがとうございます。もう一度削除して実行してみたらうまくいきまいした!お手数おかけしました。
ynakano

2016/12/22 09:13

前トピックもそうですけど、全角スペースとか入るのでしょうか? ともあれ解決したなら何よりです。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問