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

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

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

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

Linux

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

Q&A

解決済

4回答

5573閲覧

バーチャルホスト(マルチドメイン)の設定ができない

akkkkin

総合スコア83

CentOS

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

Linux

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

0グッド

0クリップ

投稿2016/12/10 02:08

編集2016/12/10 12:18

掲題の件で行き詰まっております。

■したいこと
hogehoge.comでサイトを表示させたい。

■apacheのversion
Apache/2.4.6 (CentOS)

■やったこと
httpd.confに記載した内容です。

~中略~ # least PidFile. # ServerRoot "/etc/httpd" ~中略~ #Listen 12.34.56.78:80 Listen 80 ~中略~ # Include conf.modules.d/*.conf ~中略~ # User apache Group apache ~中略~ # as error documents. e.g. admin@your-domain.com # ServerAdmin root@localhost ~中略~ #ServerName www.example.com:80 # # Deny access to the entirety of your server's filesystem. You must # explicitly permit access to web content directories in other # <Directory> blocks below. # <Directory /> AllowOverride none Require all denied </Directory> ~中略~ # #DocumentRoot "/var/www/html" # # Relax access to content within /var/www. # <Directory "/var/www"> AllowOverride All # Allow open access: Require all granted </Directory> <VirtualHost *:80> DocumentRoot /var/www/html/hogehoge ServerName hogehoge.com </VirtualHost> # Further relax access to the default document root: <Directory "/var/www/html"> # 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.4/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 All # # Controls who can get stuff from this server. # Require all granted </Directory> # # DirectoryIndex: sets the file that Apache will serve if a directory # is requested. # <IfModule dir_module> DirectoryIndex index.html </IfModule> # # The following lines prevent .htaccess and .htpasswd files from being # viewed by Web clients. # <Files ".ht*"> Require all denied # # ErrorLog: The location of the error log file. # If you do not specify an ErrorLog directive within a <VirtualHost> # container, error messages relating to that virtual host will be # ErrorLog "logs/error_log" # # LogLevel: Control the number of messages logged to the error_log. # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. # LogLevel warn <IfModule log_config_module> # # The following directives define some format nicknames for use with # a CustomLog directive (see below). # LogFormat "%h %l %u %t \"%r\" %>s %b" common <IfModule logio_module> # You need to enable mod_logio.c to use %I and %O </IfModule> # # The location and format of the access logfile (Common Logfile Format). # If you do not define any access logfiles within a <VirtualHost> # container, they will be logged here. Contrariwise, if you *do* # define per-<VirtualHost> access logfiles, transactions will be # logged therein and *not* in this file. # #CustomLog "logs/access_log" common # # If you prefer a logfile with access, agent, and referer information # (Combined Logfile Format) you can use the following directive. # CustomLog "logs/access_log" combined </IfModule> <IfModule alias_module> ~中略~ # ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" </IfModule> # # "/var/www/cgi-bin" should be changed to whatever your ScriptAliased # CGI directory exists, if you have that configured. # <Directory "/var/www/cgi-bin"> AllowOverride None Options None Require all granted </Directory> <IfModule mime_module> # # TypesConfig points to the file containing the list of mappings from # filename extension to MIME-type. # TypesConfig /etc/mime.types ~中略~ AddType application/x-compress .Z AddType application/x-gzip .gz .tgz ~中略~ AddType text/html .shtml AddOutputFilter INCLUDES .shtml </IfModule> ~中略~ AddDefaultCharset UTF-8 <IfModule mime_magic_module> # # The mod_mime_magic module allows the server to use various hints from the # contents of the file itself to determine its type. The MIMEMagicFile # directive tells the module where the hint definitions are located. # MIMEMagicFile conf/magic </IfModule> ~中略~ # (You will also need to add "Includes" to the "Options" directive.) # AddType text/html .shtml AddOutputFilter INCLUDES .shtml </IfModule> # # Specify a default charset for all content served; this enables # interpretation of all content as UTF-8 by default. To use the # default browser choice (ISO-8859-1), or to allow the META tags # in HTML content to override this choice, comment out this # directive: # AddDefaultCharset UTF-8 <IfModule mime_magic_module> # # The mod_mime_magic module allows the server to use various hints from the # contents of the file itself to determine its type. The MIMEMagicFile # directive tells the module where the hint definitions are located. # MIMEMagicFile conf/magic </IfModule> # # Customizable error responses come in three flavors: # 1) plain text 2) local redirects 3) external redirects # # Some examples: #ErrorDocument 500 "The server made a boo boo." #ErrorDocument 404 /missing.html #ErrorDocument 404 "/cgi-bin/missing_handler.pl" #ErrorDocument 402 http://www.example.com/subscription_info.html # ~中略~ #EnableMMAP off EnableSendfile on # Supplemental configuration # # Load config files in the "/etc/httpd/conf.d" directory, if any. IncludeOptional conf.d/*.conf

■その他
関係ないかもですが、/var/www/html/hogehoge/.htaccessファイルの
コードです。

# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /hogehoge/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /hogehoge/index.php [L] </IfModule> # END WordPress

■現状
DocumentRoot /var/www/html/hogehogeとしているのに
hogehoge.com/hogehogeとアクセスしないと表示されない。

hogehoge.comではhtmlディレクトリにあるindex.htmlに向いてしまう。
同階層にhogehogeディレクトリがある状態です。

■参考にしたサイト

http://www.xn--vps-073b3a72a.com/9.html

■httpd -Sで確認した実行結果
VirtualHost configuration:

*:80 hogehoge.com (/etc/httpd/conf/httpd.conf:131) ServerRoot: "/etc/httpd" Main DocumentRoot: "/var/www/html" Main ErrorLog: "/etc/httpd/logs/error_log" Mutex authdigest-opaque: using_defaults Mutex proxy-balancer-shm: using_defaults 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 PidFile: "/run/httpd/httpd.pid" Define: DUMP_VHOSTS Define: DUMP_RUN_CFG

どうすればhogehoge.comで表示できるのかご教示頂ければありがたいです。

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

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

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

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

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

退会済みユーザー

退会済みユーザー

2016/12/12 23:48

以前指摘されてなかった?ドメイン
guest

回答4

0

ベストアンサー

前にも同じような話をした記憶がある(他の方に対してかな?)のですが、ブラウザのURL欄にはどのような入力をしていますか?

また「マルチドメイン」という以上、hogehoge.com以外のドメイン設定もしているはずだと思うのですが、その話が一切出てこないのはなぜでしょうか?

投稿2016/12/10 03:27

ynakano

総合スコア1894

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

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

ynakano

2016/12/10 03:28

あと、Apacheのバージョンを記載して下さい。
akkkkin

2016/12/10 03:43

回答ありがとうございます。 Apache/2.4.6 (CentOS)です。 >hogehoge.com以外のドメイン設定 現状は他のドメインは設定しておりません。 しかし、近々設定予定があります(hogehogeと同階層にディレクトリを設置し、専用のドメイン取得)ので今からマルチドメインで設定しておきたく思います。
ynakano

2016/12/10 04:16

こちらはどうですか? > ブラウザのURL欄にはどのような入力をしていますか?
akkkkin

2016/12/10 04:50

hogehoge.comhogehoge.com/hogehoge と両方のパターン入力しています。 ・hogehoge.comの場合 var/www/htmlのindex.htmlに向く ・hogehoge.com/hogehogeの場合 var/www/html/hogehogeに向く といった状況です。
ynakano

2016/12/10 06:00

httpd -Sの結果を見る限り、バーチャルホスト設定が認識されていないようです。 認識されていれば以下のような表示が存在するはずです。 port 80 namevhost hogehoge.jp 済みませんが質問を編集して、最新のhttpd.confを記載してもらえますか。 ※バーチャルホスト設定は外部confのIncludeではなくhttpd.confに記載している、でいいのですよね。
ynakano

2016/12/10 06:18

回答と直接関係ないのですが、記載上気になる点があります。 ※設定ファイルの記載ではなく回答文の記載について。 "var/www/html/hogehoge"という書き方が目につくのですが、これだと「カレントディレクトリ配下の"var/www/html/hogehoge"」という意味になります。(相対パス) つまり文脈次第でどのディレクトリを指すかが変わってしまうことになります。 ルートディレクトリからたどった"var/www/html/hogehoge"であるなら、先頭のスラッシュをきちんと記載して絶対パス指定で"/var/www/html/hogehoge"としてください。 設定ファイルはきちんと書かれているようなので、それが意図通りに動作しない原因ではないですが。
yunano

2016/12/10 06:26

私の手元のCentOS 7 / httpd-2.4.6-40.el7.centos.4.x86_64でバーチャルドメインをこの質問のために設定してみて特に問題が出ていない環境で、httpd -Sを打つと以下のようになるので、設定は正しい気がするのです。 VirtualHost configuration: *:80 hogehoge.com (/etc/httpd/conf/httpd.conf:355) ServerRoot: "/etc/httpd" Main DocumentRoot: "/etc/httpd/htdocs" Main ErrorLog: "/etc/httpd/logs/error_log" (以下略) ただもちろん、/etc/httpd/conf/httpd.confの全文晒してもらうのは賛成です。
ynakano

2016/12/10 08:22

yunanoさん ご指摘ありがとうございます。 私の手元が2.6だったので、ググった情報ベースでのコメントでした。 いずれにしてもhttpd.conf待ちですね。
akkkkin

2016/12/10 08:33

httpd.confを記載を変更しました。 よろしくお願いします。
ynakano

2016/12/10 10:05

済みません。どこですか?
akkkkin

2016/12/10 10:10

わかりにくい記載で申し訳ありません。 「やったこと」という項目です。 「httpd.confに記載した内容」という文言も追記しました。
ynakano

2016/12/10 10:13

ではなくて、httpd.conf全体です。 もちろんボカすところはボカすでいいのですが、今の記載内容だと何が原因か全く分かりません。
ynakano

2016/12/10 10:26

yunanoさん 申し訳ないです。Apacheのバージョンを勘違いしてました・・・
ynakano

2016/12/10 10:55

Apacheのバージョンで血迷ったことを書いたお詫びにApache 2.4.6でテストしてみました。 Apache2.2と書きたかったのに・・・ > yunanoさん 私が15:00に書いた「port 80 namevhost hogehoge.jpと表示されるはずでは」というコメントですが、バーチャルホストを複数設定した場合の挙動のようです。 バーチャルホスト設定が一つだけの場合はyunanoさんのおっしゃる通りの出力でした。
yunano

2016/12/10 10:59

ynakanoさん、確認ありがとうございます。承知しました。
akkkkin

2016/12/10 12:19

回答ありがとうございます。 >httpd.conf全体です。 投稿行数の関係上中略いれましたが修正しました。
ynakano

2016/12/10 12:44

ありがとうございます。 同一Apacheバージョンで設定も同じにしてるんですが、再現しないんですよね。 くどいようですがクライアント(アクセスしているPC)側について確認させて下さい。 以下2点です。 このWebサーバにアクセスするときブラウザを使っているはずですが、そのURL欄に入力されている内容を"http://"から1文字も略さずに記載していただけないですか。 また、ブラウザのURL欄に"http://<WebサーバのIPアドレス>"と入力するとどのような画面が表示されますか?
akkkkin

2016/12/10 12:50

>そのURL欄に入力されている内容を"http://"から1文字も略さずに記載していただけないですか。 → http://hogehoge.com/  >ブラウザのURL欄に"http://<WebサーバのIPアドレス>"と入力するとどのような画面が表示されますか? → 真っ白です。 なぜなら"/var/www/htmlのindex.html"に向いているからです。 ※index.htmlファイルの中身は何も入っていません。
ynakano

2016/12/10 13:06

ありがとうございます。 質問文には「hogehoge.comではhtmlディレクトリにあるindex.htmlに向いてしまう。」とあるのですが、つまりこれはIPアドレス指定でアクセスしたとき同様、真っ白になってしまうということでしょうか。 また、hogehoge.comに関するバーチャルホスト設定【より上に】以下のような設定を追加して動作確認をしてみてはどうでしょうか。 <VirtualHost *:80> ServerName 【サーバのIPアドレス】 DocumentRoot /var/www2/html </VirtualHost> "/var/www2/html"とその下に置くindex.htmlは新規作成。 index.htmlの中身は分かりやすく判別がつくような内容にする。 設定追加、Apache再起動の後に"http://hogehoge.com/"と"http://<IPアドレス>/"両方でアクセスをして、どう表示されるか試してみてください。 また、その際のhttpd -Sの結果もいただけないでしょうか。
akkkkin

2016/12/10 17:22 編集

上記の設定を追加しました。 "/var/www2/html"とその下に置くindex.html→中身はtestと記載 "/var/www/html"とその下に置くindex.html→中身はhogehogeと記載 ■httpd.confに以下のコードを記述 <VirtualHost *:80> ServerName IPアドレス DocumentRoot /var/www2/html </VirtualHost> ■Apache再起動後の結果 "http://hogehoge.com/"と"http://<IPアドレス>/"両方ともhogehogeと表示。 ■httpd -Sの結果 AH00112: Warning: DocumentRoot [/var/www2/html] does not exist VirtualHost configuration: *:80 is a NameVirtualHost default server hogehoge.com (/etc/httpd/conf/httpd.conf:131) port 80 namevhost hogehoge.com (/etc/httpd/conf/httpd.conf:131) port 80 namevhost IPアドレス (/etc/httpd/conf/httpd.conf:136) ServerRoot: "/etc/httpd" Main DocumentRoot: "/etc/httpd/htdocs" Main ErrorLog: "/etc/httpd/logs/error_log" 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 Mutex proxy: using_defaults Mutex authn-socache: using_defaults Mutex default: dir="/run/httpd/" mechanism=default 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 以上となります。
ynakano

2016/12/10 21:43

httpd -Sの結果に「AH00112: Warning: DocumentRoot [/var/www2/html] does not exist」とあります。 "/var/www2/html"ディレクトリがないという意味です。 ディレクトリは正しく作成していますか? 私の意図としてはhttpd -S実行時の"default server"が<IPアドレス>になるはずだったのですが、上記エラーのせいかhogehoge.comがdefault serverになっているようです。 ※httpd.confではIPアドレスに関するVirtualHost設定がhogehoge.comのそれよりも上の行に書かれてますよね? また、以下のコマンド結果はどうなりますか? ls -al /var/www2/html ls -al /var/www/html ls -al /var/www/html/hogehoge ※ディレクトリはスラッシュで始まるフルパス指定です。 ※下の2つは念のため 最後に、設定ファイルを編集したらapachectl configtestをするようにしてください。 設定ファイルの記述ミスはこれで検出できます。 "Syntax OK"と【だけ】表示されればOKです。
akkkkin

2016/12/12 02:28

>ディレクトリは正しく作成していますか? はい、作成しています。 >httpd.confではIPアドレスに関するVirtualHost設定がhogehoge.comのそれよりも上の行に書かれてますよね? いえ、上の行にカイていなかったので、修正しました。順番は下記にしました。 ーーーーーー <VirtualHost *:80> DocumentRoot /var/www/html/hoge ServerName hogehoge.com </VirtualHost> <VirtualHost *:80> ServerName <IPアドレス> DocumentRoot /var/www2/html </VirtualHost> ーーーーーー ■httpd -Sの実行結果 下記になりました。また"/var/www2/html"がないと表示されているようですが作成しているんですけどね。 ーーーーーー AH00112: Warning: DocumentRoot [/var/www2/html] does not exist VirtualHost configuration: *:80 is a NameVirtualHost default server <IPアドレス> (/etc/httpd/conf/httpd.conf:131) port 80 namevhost <IPアドレス> (/etc/httpd/conf/httpd.conf:131) port 80 namevhost hogehoge.com (/etc/httpd/conf/httpd.conf:136) ServerRoot: "/etc/httpd" Main DocumentRoot: "/etc/httpd/htdocs" Main ErrorLog: "/etc/httpd/logs/error_log" 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 Mutex proxy: using_defaults Mutex authn-socache: 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 ーーーーーー ■ls -al /var/www2/htmlの実行結果 ls: cannot access /var/www2/html: No such file or directory ■■ls -al /var/www2/htmlの実行結果 drwxrwxr-x. 3 apache user 37 Dec 11 02:02 . drwxr-xr-x. 4 root root 31 Nov 6 17:35 .. drwxrwxr-x. 5 apache user 4096 Dec 11 15:23 hogehoge -rwxrwxr-x. 1 apache user 9 Dec 11 02:02 index.html ■apachectl configtestの実行結果 AH00112: Warning: DocumentRoot [/var/www2/html] does not exist Syntax OK となりました。 ”/var/www2/htmlにindex.html”まで作成しているのに、ディレクトリがないという結果が返ってきているようです。
ynakano

2016/12/12 03:21

まず指摘です。 ・バーチャルホストの記載順はhogehoge.comが上ではないのですか?コメントと整合性がとれないです。 ・「■■ls -al /var/www2/htmlの実行結果」は書き間違えですよね。 さて、本当に(何かの誤解や間違えではなく)作成したはずのディレクトリがないのなら、バーチャルホストがどうこうという以前にサーバがおかしいですね。 念のため、再度以下確認してはどうでしょうか。 rootユーザで以下のコマンドを実行してください。 find / -name www2 あと、以下もお願いできればと思います。 ls -al /var/www/html/hogehoge
akkkkin

2016/12/12 03:49

回答ありがとうございます。 >バーチャルホストの記載順はhogehoge.comが上ではないのですか? 失礼しました。コメントの記載が逆でした。 httpd.confファイルは下記で設定しています。 ーーーーーーー <VirtualHost *:80> ServerName <IPアドレス> DocumentRoot /var/www2/html </VirtualHost> <VirtualHost *:80> DocumentRoot /var/www/html/hoge ServerName hogehoge.com </VirtualHost> ーーーーーーー >find / -name www2 ”/var/www2”と結果がかえってきました。 >ls -al /var/www/html/hogehoge total 220 drwxrwxr-x. 5 apache user 4096 Dec 11 15:23 . drwxrwxr-x. 3 apache user 37 Dec 11 02:02 .. -rw-rw-r--. 1 user user 252 Dec 10 13:02 .htaccess -rwxrwxr-x. 1 apache user 418 Sep 25 2013 index.php -rwxrwxr-x. 1 apache user 19935 Mar 6 2016 license.txt -rwxrwxr-x. 1 apache user 10214 Sep 9 21:50 readme.html -rwxrwxr-x. 1 apache user 5456 May 25 2016 wp-activate.php drwxrwxr-x. 9 apache user 4096 Sep 9 21:50 wp-admin -rwxrwxr-x. 1 apache user 364 Dec 19 2015 wp-blog-header.php -rwxrwxr-x. 1 apache user 1477 May 24 2016 wp-comments-post.php -rwxrwxr-x. 1 apache user 3818 Dec 10 12:25 wp-config.php -rwxrwxr-x. 1 apache user 20480 Nov 8 17:32 .wp-config.php.swp -rwxrwxr-x. 1 apache user 3834 Sep 9 21:50 wp-config-sample.php drwxrwxr-x. 9 apache user 4096 Dec 11 02:58 wp-content -rwxrwxr-x. 1 apache user 3286 May 25 2015 wp-cron.php drwxrwxr-x. 17 apache user 8192 Sep 9 21:50 wp-includes -rwxrwxr-x. 1 apache user 2382 May 24 2016 wp-links-opml.php -rwxrwxr-x. 1 apache user 3353 Apr 15 2016 wp-load.php -rwxrwxr-x. 1 apache user 34057 Jun 15 06:51 wp-login.php -rwxrwxr-x. 1 apache user 7786 Jul 13 21:37 wp-mail.php -rwxrwxr-x. 1 apache user 13920 Aug 14 01:02 wp-settings.php -rwxrwxr-x. 1 apache user 29890 May 25 2016 wp-signup.php -rwxrwxr-x. 1 apache user 4035 Dec 1 2014 wp-trackback.php -rwxrwxr-x. 1 apache user 3064 Jul 6 21:40 xmlrpc.php と返ってきました。
ynakano

2016/12/12 04:01

ありがとうございます。 では以下はどうですか? ls -alR /var/www2
akkkkin

2016/12/12 04:09

回答ありがとうございます。 >ls -alR /var/www2 以下の結果が返ってきました。 /var/www2: total 8 drwxr-xr-x. 2 root root 23 Dec 11 01:54 . drwxr-xr-x. 21 root root 4096 Dec 11 01:53 .. -rw-r--r--. 1 root root 5 Dec 11 01:54 index.html
ynakano

2016/12/12 04:17

httpd.confに記述したのは「/var/www2/html」ですからhtmlディレクトリがないですね。 /var/www2の直下にhtmlディレクトリを作成して、index.htmlをhtmlディレクトリの下に移動させましょう。 12:49の回答を見て感じたのですが、phpや.htaccessなど問題の切り分けを複雑化する要因があるように思います。 一度hogehoge.comのDocument Rootを新しく作成し(eg: /var/www/html/hogehoge2)、そこのindex.htmlファイルだけを置いて動作確認してみたらどうですか? あと、また指摘です。 hogehoge.comのドキュメントルート、「DocumentRoot /var/www/html/hoge」は誤りですよね。 ※やり取りの上で転記ミス(ですかね?)が多い気がします。読む側はそれが設定誤りの原因なのか単なる記述ミスなのか、無用な思考が発生します。 ターミナルからコピペできるのならそうしてもらえればと思います。
akkkkin

2016/12/12 04:50 編集

>var/www2の直下にhtmlディレクトリを作成して、index.htmlをhtmlディレクトリの下に移動させましょう。 申し訳ありません。設定ミスでした。 ”/var/www2/html/index.html”としました。 >hogehoge.comのDocument Rootを新しく作成し(eg: /var/www/html/hogehoge2)、そこのindex.htmlファイルだけを置いて動作確認 ・http://<IPアドレス>/hogehoge2/index.htmlでアクセス Forbidden You don't have permission to access /hogehoge2/index.html on this server.と表示 ・http://<IPアドレス>/hogehoge2でアクセス Forbidden You don't have permission to access /hogehoge2 on this server.と表示 ・http://hogehoge.com/hogehoge2でアクセスhttp://hogehoge.com/hogehoge2/index.htmlでアクセス Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error. More information about this error may be available in the server error log.と表示 >やり取りの上で転記ミス(ですかね?)が多い気がします 申し訳ございません。転記ミス、設定ミス気をつけます。
ynakano

2016/12/12 05:01

「”/var/www2/html/index.html”としました。」というのはhtmlディレクトリを作成してindex.htmlファイルを移動させた、という事でよいでしょうか? Forbiddenはディレクトリやファイルの所有者権限が原因でしょうか。 "/var/www/html/hogehoge"配下が"apache:user"となっているので、それに倣って以下の通り設定してみてください。 chown -R apache:user /var/www2/html chown -R apache:user /var/www/html/hogehoge2 後は"apachctrl configtest"、httpdの再起動、httpd -Sを一通り確認してからアクセスしてみてください。
akkkkin

2016/12/12 06:03

回答ありがとうございます。 >「”/var/www2/html/index.html”としました。」というのはhtmlディレクトリを作成してindex.htmlファイルを移動させた、という事でよいでしょうか? はい、そうです。 >chown -R apache:user /var/www2/html >chown -R apache:user /var/www/html/hogehoge2 設定しました。 apacheの再起動も行いました。 >"apachectrl configtest" Syntax OK >httpd -S VirtualHost configuration: *:80 is a NameVirtualHost default server <IPアドレス> (/etc/httpd/conf/httpd.conf:131) port 80 namevhost <IPアドレス> (/etc/httpd/conf/httpd.conf:131) port 80 namevhost hogehoge.com (/etc/httpd/conf/httpd.conf:136) ServerRoot: "/etc/httpd" Main DocumentRoot: "/etc/httpd/htdocs" Main ErrorLog: "/etc/httpd/logs/error_log" 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 Mutex proxy: using_defaults Mutex authn-socache: using_defaults Mutex default: dir="/run/httpd/" mechanism=default 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 ただ、現在hogehoge.com/hogehogeも繋がらなくなりました。
akkkkin

2016/12/12 06:10

>「”/var/www2/html/index.html”としました。」というのはhtmlディレクトリを作成してindex.htmlファイルを移動させた、という事でよいでしょうか? 申し訳ありません。まだ上記がうまく設置できておりませんでしたので、再設置してからコメント致します。
akkkkin

2016/12/12 06:26

>申し訳ありません。まだ上記がうまく設置できておりませんでしたので、再設置してからコメント致します。 申し訳ありません。ちゃんと設置されておりました。 上記の結果は同じです。
ynakano

2016/12/12 06:49

済みません。 何をやってどうなったかが読み取りづらいです。 ブラウザで次のURLを入力するした場合、ブラウザはどのような表示になりますか? http://<WebサーバのIPアドレス>/ http://hogehoge.com/
akkkkin

2016/12/12 14:44 編集

読み取りづらくて申し訳御座いません。 >http://<WebサーバのIPアドレス>/ Apache HTTP server test pageにつながります。 >http://hogehoge.com/ トップページは表示できました。しかし、トップページから各ページのリンクが全てつながりません。Internal Server Errorとなります。ちなみにサイトはWordPressで作っております。原因はパーマリンクかと思い、管理ページからパーマリンク設定ページにいき、保存ボタンをクリックして更新しましたが、ダメでした。
ynakano

2016/12/12 14:50

と言うことは、少なくともバーチャルホスト、つまりアクセスされたFQDNに応じたコンテンツの出し分けについてはできたと言うことになりますね。 コメントにある、「トップページからのリンクがつながらない」「Internal Server Error」「パーマリンク云々」の話は「バーチャルホスト」「マルチドメイン」とは別の話になります。 コンテンツの作りの問題なのか、配置しているディレクトリがズレているのか、はたまたWordPressの設定の問題なのか、そこは別途確認する必要があるとは思います。 ですので、その質問についてはトピックを分けていただくべきだと思います。
akkkkin

2016/12/12 15:07 編集

>トップページは表示できました。しかし、トップページから各ページのリンクが全てつながりません。 .htaccessが原因でした。解決しました。 あとは、 http://<WebサーバのIPアドレス>/ Apache HTTP server test pageにつながる件の解消だけです。
ynakano

2016/12/12 23:29

今の設定では"IPアドレス"部分のVirtualhost設定はどうなっているのでしょうか?
akkkkin

2016/12/13 00:21

回答ありがとうございます。 <VirtualHost *:80> ServerName "IPアドレス" DocumentRoot /var/www2/html </VirtualHost> となっております。
ynakano

2016/12/13 00:43

index.htmlは存在してますよね? であれば、一度ブラウザ側でキャッシュを削除してアクセスしてみる、また、ctrl+F5でリロードしてみますか。
akkkkin

2016/12/13 01:00

>index.htmlは存在してますよね? "/var/www2/html"の中にindex.htmlがあります。 >ctrl+F5でリロードしてみますか。 Testing 123..とapacheの画面になります。 以下質問です。 ・www2は必要なのでしょうか。 ・/var/www/html/hogehoge2は必要なのでしょうか。
ynakano

2016/12/13 01:11

質問についてです。 "...2"のコンテンツやディレクトリは、問題箇所を絞り込むための切り分け用という意図です。 不要ということなら削除していただいて構いません。
akkkkin

2016/12/13 08:17

回答有り難うござます。 切り分けようということですね。ではそのまま残しておきます。 http://<WebサーバのIPアドレス>/の表示が Testing 123..となる件についてです。 >chown -R apache:user /var/www2/html リロードしてもTesting 123..とapacheとapacheの画面が表示されるので、 上記のコマンドを実行し、再起動をはかっても同じでした。
ynakano

2016/12/13 12:59

一応"ls -alR /var/www2"をしてみていただけないですか。
akkkkin

2016/12/15 01:50

回答ありがとうござあいます。 下記になります。 /var/www2: total 4 drwxr-xr-x. 3 root root 17 Dec 12 15:14 . drwxr-xr-x. 21 root root 4096 Dec 12 23:53 .. drwxr-xr-x. 2 apache user 23 Dec 12 15:17 html /var/www2/html: total 4 drwxr-xr-x. 2 apache user 23 Dec 12 15:17 . drwxr-xr-x. 3 root root 17 Dec 12 15:14 .. -rw-r--r--. 1 apache user 5 Dec 12 13:32 index.html
ynakano

2016/12/15 03:44

調べてみて判明しました。結論から言うと私のお願いした「切り分け用ディレクトリ」が良くなかったです。 意図通り動作させるには以下のいずれかの方法を取る必要があります。 1) 全てのコンテンツを"/var/www"の下におく。 2) "/var/www"以外に置くなら(例えば"/var/www2")、httpd.confに以下の記述を足す。 <Directory "/var/www2"> Require all granted </Directory> httpd.confの設定上、以下の記述によって一度全てのディレクトリへのアクセス権を剥奪します。 <Directory /> Require all deny </Directory> その後で必要なディレクトリについてのみ"Require all granted"でアクセス許可を出します。 で、アクセス許可のないディレクトリをリクエストするとどうなるかと言うと、"[httpdディレクトリ]/conf.d/welcome.conf"の設定に従って、Testing123のページに飛ばされます。 私から"/var/www2/html"を作って下さいとお願いはしたものの、<Directory>ディレクティブでgrantしていなかったため、Testing123に飛ばされていたと言うわけです。 不完全なお願いをしたばっかりに振り回してしまって申し訳ないです。 ただ、よかったら今のhttpd.confに <Directory "/var/www2"> Require all granted </Directory> と書き足してApacheを再起動して、動きが変わるのを確認してみてください。
akkkkin

2016/12/15 06:15

回答有り難うございまうす。 <Directory "/var/www2"> Require all granted </Directory> をhttpd.confに足しました。 再起動後、<IPアドレス>だけでアクセスすると、 同じくTesting123になります。
ynakano

2016/12/15 08:02

私の手元だと"Require all granted"の1行をコメントアウトするだけで動作が変わるのを確認しているのですが・・・ ブラウザキャッシュ削除や[ctrl]+[F5]更新しても同じですか?
akkkkin

2016/12/15 10:30

>私の手元だと"Require all granted"の1行をコメントアウトするだけで動作が変わる これはどういうことでしょうか? 修正前 <Directory "/var/www2"> Require all granted </Directory> を 修正後 <Directory "/var/www2"> #Require all granted </Directory> にするということでしょうか?
ynakano

2016/12/15 10:32

はい、その通りです。 前者の場合は"/var/www2/html/index.html"が表示されて、後者の場合はTesting123が表示されます。
akkkkin

2016/12/15 10:38

回答ありがとうございます。 やはり同じくTesting123になります。 リロードしても同じでした。 ブラウザも変えましたが同じでした。
ynakano

2016/12/15 10:49

以下を丸ごとhttpd.confとしてみたらどうなりますか? ~~~~~~~~~ここから~~~~~~~~~ Listen *:80 Include conf.modules.d/*.conf User apache Group apache ServerAdmin root@localhost ServerName localhost.localdomain:80 <Directory /> AllowOverride none Require all denied </Directory> <Directory "/var/www"> AllowOverride None Require all granted </Directory> <Directory "/var/www2"> AllowOverride All Require all granted </Directory> <VirtualHost *:80> ServerName 192.168.0.101 DocumentRoot /var/www2/html </VirtualHost> <VirtualHost *:80> DocumentRoot /var/www/html/hogehoge ServerName hogehoge.com </VirtualHost> <Directory "/var/www/html"> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> <IfModule dir_module> DirectoryIndex index.html </IfModule> <Files ".ht*"> Require all denied </Files> ErrorLog "logs/error_log" LogLevel warn <IfModule log_config_module> LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat "%h %l %u %t \"%r\" %>s %b" common <IfModule logio_module> LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio </IfModule> CustomLog "logs/access_log" combined </IfModule> <IfModule alias_module> ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" </IfModule> <Directory "/var/www/cgi-bin"> AllowOverride None Options None Require all granted </Directory> <IfModule mime_module> TypesConfig /etc/mime.types AddType application/x-compress .Z AddType application/x-gzip .gz .tgz AddType text/html .shtml AddOutputFilter INCLUDES .shtml </IfModule> AddDefaultCharset UTF-8 <IfModule mime_magic_module> MIMEMagicFile conf/magic </IfModule> EnableSendfile on IncludeOptional conf.d/*.conf ~~~~~~~~~ここまで~~~~~~~~~ 私の環境で動いているもの(からコメント行を削除したもの)です。 補足としては以下の通りです。 ・1箇所だけ変更が必要です。VirtualHostのIPアドレスの部分です。ご自身のIPに置き換えてください。後は一文字たりとも変更する必要はないはずです。 ・<Directory "/var/www2">のAllowOverrideはあってもなくても問題ないはずです。(今回の話題の範囲に限って言えば) 言うまでもないですがファイルの差し替えをするなら元のファイルはバックアップしましょう。 また、apachectl configtestも忘れずに。
akkkkin

2016/12/15 11:20

表示できました!ありがとうございます。 ちなみに以下が編集前編集後なのですが、どこに問題があったのでしょうか? [修正前] <Directory "/var/www"> AllowOverride All Require all granted </Directory> [修正後] <Directory "/var/www"> AllowOverride None Require all granted </Directory> ーーーーーー [修正前] <Directory "/var/www2"> Require all granted </Directory> [修正後] <Directory "/var/www2"> AllowOverride All Require all granted </Directory> ーーーーーー [修正前] <Directory "/var/www/html"> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> [修正後] <Directory "/var/www/html"> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory>
ynakano

2016/12/15 11:25

・・・見た限り今回の問題に影響しそうな違いは見当たらないですね。 見た目に分からないヘンな文字(制御コード)が入っているとか?
akkkkin

2016/12/16 03:42

上記Allの箇所をNoneにしても何ら影響はないのでしょうか? 本当に丁寧に解説してくださり、感謝しております。
ynakano

2016/12/16 03:48

済みません。その点補足します。 結論から言うと"/var/www2"のAllowOverrideの値は動作切り分けのためにいじっているだけです。(で、バーチャルホスト動作に影響がないことを確認した訳です) この値をどうするかはhtaccessを使うか使わないかによりますが、もともと"/var/www2"が切り分け用ディレクトリなので.htaccessは使わないと思います。 なのでNoneにして(戻して?)も問題ないと思います。
guest

0

名前ベースのバーチャルホストの設定は下記記事が参考になるかと思いますのでご確認ください。
(ポート番号は80番で設定して下さい。)
また、設定後はhttpd -Sコマンドで設定したバーチャルホストを確認すると良いかと思います。
ご確認のほど、宜しくお願い致します。

▼ 名前ベースの仮想ホスト
http://www.adminweb.jp/apache/virtual/index2.html
▼ バーチャルホストの一覧を見るには
http://www.ksknet.net/apache/post_49.html

投稿2016/12/10 02:37

pond

総合スコア350

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

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

akkkkin

2016/12/10 02:53

回答ありがとうございます。httpd -Sコマンドの実行結果を質問に追記しました。
akkkkin

2016/12/15 11:31

上記Allの箇所をNoneにしても何ら影響はないのでしょうか? 本当に丁寧に解説してくださり、感謝しております。
guest

0

設定してるのは hogehoge.com:10022 ですよね。
hogehoge.com:80の設定ではないので
デフォルト設定の DocumentRoot /var/www/html を通っているのでは?

投稿2016/12/10 02:22

退会済みユーザー

退会済みユーザー

総合スコア0

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

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

akkkkin

2016/12/10 02:31

ポートは10022 です。10022で設定してもダメでした。 index.htmlに向いてしまってます。
pond

2016/12/10 02:38

横やりで申し訳ありませんm(__)m 10022はsshのポート番号なので、apacheとは関係ないです。
akkkkin

2016/12/10 02:54

最初80にしてましたがうまくいかなかったので、10022のポートに修正したのでした。 再度80に戻し再起動もしたのですが、index.htmlに向いてしまってます。
pond

2016/12/10 03:15

httpd.confにデフォルトで設定されてるDocumentRootは、コメントアウトしましたか? DocumentRoot "/var/www/html" を ↓コメントアウトします。 #DocumentRoot "/var/www/html"
akkkkin

2016/12/10 03:27 編集

ありがとうございます。コメントアウトしてませんでした。 >#DocumentRoot "/var/www/html" しかしコメントアウトしてもダメでした。再起動もしています。 index.htmlに向いてしまってます。
guest

0

最小だと

<VirtualHost *:80> DocumentRoot /var/www/html/hogehoge ServerName hogehoge.com </VirtualHost>

で行けます。

https://httpd.apache.org/docs/2.2/ja/vhosts/examples.html を参照して下さい。

投稿2016/12/10 02:21

yunano

総合スコア841

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

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

akkkkin

2016/12/10 02:29

回答ありがとうございます。上記実行してみたところ、ダメでした。 htmlディレクトリにあるindex.htmlに向いてしまいます。 ポートは80になってますが、SSHでログインするときのポートは10022ですので 10022でいいのでしょうか?
yunano

2016/12/10 02:39

SSHで使う10022は使ってはいけません。それはSSHのためのものでHTTPのためのものではありません。 httpdで使用するHTTPのポートは通常80です。 httpd.confの修正後、httpdの再起動は行われましたでしょうか。 また、ブラウザからhttp://hogehoge.com/にアクセスしているのですよね?
akkkkin

2016/12/10 02:49

回答有り難うございます。 80に戻しました。再起動は随時変更したらおこなっております。 ブラウザからhttp://hogehoge.com/にアクセスしております。 まだ、index.htmlに向いてしまってます。
yunano

2016/12/10 02:54

修正した設定ファイルは /etc/httpd/conf/httpd.conf で合ってますでしょうか。 また、他の方の回答にあるように httpd -S を実行したらどのような表示がされますか。
akkkkin

2016/12/10 03:31

httpd.confであっております。 下記の表示になりました。 #DocumentRoot "/var/www/html"としたらドキュメントルート先が Main DocumentRoot: "/var/www/html"だったのに下記に変わっております。 VirtualHost configuration: *:80 hogehoge.com (/etc/httpd/conf/httpd.conf:131) ServerRoot: "/etc/httpd" Main DocumentRoot: "/etc/httpd/htdocs" Main ErrorLog: "/etc/httpd/logs/error_log" 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 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 not_used Group: name="apache" id=48 not_used
yunano

2016/12/10 03:35

設定はできているように見えますね。ならば、 * ブラウザのキャッシュに残っているものが見えている http://www.netyasun.com/browser/reload.html を参考にスーパーリロードしてみて下さい。 * ブラウザがhogehoge.comを別のサーバに見に行っている hogehoge.comの解決をどのように行っているかわかりませんが、例えばhostsファイルで行っている場合はhostsファイルの設定を見直して下さい。
yunano

2016/12/10 03:56

いつの間にか.htaccessファイルの情報が追加されていますね。 もう出掛けないとならないので内容の精査はしていませんが、一旦.htaccessファイルを他のディレクトリに除けておいて確認してみて下さい。
akkkkin

2016/12/10 04:03

お忙しいところありがとうございます。 >htaccessファイルを他のディレクトリに除けておいて確認してみて下さい 一旦削除してアクセスしてみましたが、ダメでした。 かわらずindex.htmlに向いてしまってます。
yunano

2016/12/10 05:21

だとするとブラウザ側の問題のような気がするのですが、.htaccessの1つ前に書いたこれらはどうだったでしょうか。 * ブラウザのキャッシュに残っているものが見えている http://www.netyasun.com/browser/reload.html を参考にスーパーリロードしてみて下さい。 * ブラウザがhogehoge.comを別のサーバに見に行っている hogehoge.comの解決をどのように行っているかわかりませんが、例えばhostsファイルで行っている場合はhostsファイルの設定を見直して下さい。
akkkkin

2016/12/10 08:07

回答有り難うございます。 * ブラウザのキャッシュに残っているものが見えている →リロードしましたがダメでした。 * ブラウザがhogehoge.comを別のサーバに見に行っている →別のサーバーはありませんので、これは考えにくいです。
yunano

2016/12/10 12:35

ブラウザはどのOSの何というブラウザですか?
akkkkin

2016/12/10 12:44

Google Chrome OSです。
yunano

2016/12/10 12:49

CentOS側で/etc/hostsに次の1行を追加して、 127.0.0.1 hogehoge.com その後に curl http://hogehoge.com/ を実行するとどちらのページの内容が表示されますか?
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問