LoginSignup
30
33

More than 5 years have passed since last update.

MacでのApacheのVirtualHost設定で気をつけること

Posted at

このドキュメントについて

MacでVirtualHostを設定して、複数のローカルサイトを別ドメインでみたい場合の設定

最終的な設定内容

/etc/hostsの設定


127.0.0.1   a.test.jp
127.0.0.1   b.test.jp

/etc/apache2/httpd.confの設定

変更なし

/etc/hosts


127.0.0.1       a.test.jp b.test.jp localhost
::1             a.test.jp b.test.jp localhost

/etc/apache2/other/httpd-vhosts.conf


Listen 80
NameVirtualHost *:80

<VirtualHost *:80>
    ServerName     a.test.jp
    DocumentRoot   "/Users/hoge/a"
    CustomLog      "/var/log/a-error_log" common
    ErrorLog       "/var/log/a-error_log"
    <Directory "/Users/hoge/a">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
    </Directory>
</VirtualHost>
<VirtualHost *:80>
    ServerName     b.test.jp
    DocumentRoot   "/Users/hoge/b"
    CustomLog      "/var/log/b-error_log" common
    ErrorLog       "/var/log/b-error_log"
    <Directory "/Users/hoge/b">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
    </Directory>
</VirtualHost>

途中でいくつかひっかかったときのこと

apacheを再起動してもエラーが標準出力されない


httpd -S

でエラーがでていないか確認

/etc/apache2/extraをincludeするとssl証明書関連でエラー

最初、httpd.confで/etc/apache2/extra/*をIncludeしてしていたが、ssl関連ファイルでエラーがでるので、読み込みが必要なファイルのみ/etc/apache2/othersにコピーして使用


Include /private/etc/apache2/other/*.conf

上記の行はデフォルトで書かれているので、追記する必要はなし

httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

httpd.confのServerNameの設定をしていないため。

ServerNameに127.0.0.1を使用した、FQDN(ドメイン名)が確定できませんでした。
Apacheの設定と、サーバ自身の名前の設定と、それに紐付けられたIPの設定を同じにしないと上記のメッセージがでます。

  • /etc/apache2/httpd.conf

ServerName localhost:80
  • /etc/hosts

127.0.0.1       a.test.jp b.test.jp localhost
::1             a.test.jp b.test.jp localhost

stackoverflowでのVirtualHostが動作しない関連の投稿

このあたりを疑ってみる。

参考

おまけ

東洋経済オンラインで「エンジニア夫婦のあるある日記」を連載中です

エンジニア夫婦のあるある日記

あるある日記.jpg

30
33
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
30
33