Apacheエラー「httpd: apr_sockaddr_info_get()」、「httpd: Could not reliably determine the server's fully qualified domain name」のエラーの原因と解決方法
CentOS 6にインストールされているhttpdを起動してみると、
apr_sockaddr_info_get() failed
Could not reliably determine the server's fully qualified domain name
といったエラーが発生することに気づいた。
《実行コマンド》
[root@test ~]# /etc/rc.d/init.d/httpd statu ←Apacheの実行状況確認
httpd は停止しています
[root@test ~]# /etc/rc.d/init.d/httpd start ←Apacheの起動
httpd を起動中: httpd: apr_sockaddr_info_get() failed for test.centos6
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[ OK ] ←エラーは出るが、起動には成功する。
エラーメッセージから推測すると、「ServerName」についてのエラーのようなので、「ServerName」の設定を確認する。
[root@test ~]# vi /etc/httpd/conf/httpd.conf
《httpd.confの「ServerName」に関する設定記述抜粋》
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If this is not set to valid DNS name for your host, server-generated
# redirections will not work. See also the UseCanonicalName directive.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
# You will have to access it by its address anyway, and this will make
# redirections work in a sensible way.
#
#ServerName www.example.com:80
「ServerName」の設定箇所は、コメントになっていた。
「ServerName」の設定がコメントになっている場合の、デフォルト値(初期値)が何になるかは分からなかったので、Apacheのマニュアルを見てみる。
ServerName が指定されていないときは、 サーバは IP アドレスから逆引きを行なうことでホスト名を知ろうとします。
■参考サイト
Apache > HTTP サーバ > ドキュメンテーション > バージョン 2.2 > モジュール > ServerName ディレクティブ
http://httpd.apache.org/docs/2.2/ja/mod/core.html#servername)
Apacheがどうやって「IP アドレスから逆引きを行なうことでホスト名を知ろうと」しているかは分からなかったが、Apacheのエラーメッセージ
httpd: apr_sockaddr_info_get() failed for test.centos6
から推測すると、Apacheが認識したサーバのホスト名は「test.centos6」であり、このホスト名に原因があってエラーになっていることが分かる。
試しに、Apacheが認識したホスト名にpingを実行してみる。
[root@test ~]# ping test.centos6
ping: unknown host test.centos6
不明なホストというメッセージが返ってくる。
「test.centos6」については、CentOS 6をインストールする際に私が設定したものなので、設定を確認。
[root@test ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=test.centos6
[root@test ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
/etc/hostsに、「test.centos6」を追加してみる。(/etc/hostsはviで編集する。)
[root@test ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 test.centos6
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
再度、pingを実行してみる。
[root@test ~]# ping test.centos6
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.019 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.068 ms
「test.centos6」の名前解決ができるようになった。
これでエラーが出なくなるかな、と思って、Apacheを再起動してみる。
[root@test ~]# /etc/rc.d/init.d/httpd restart
httpd を停止中: [ OK ]
httpd を起動中: httpd: Could not reliably determine the server's fully qualified domain name, using test.centos6 for ServerName
[ OK ]
「apr_sockaddr_info_get() failed」のエラーは出なくなったが、
「Could not reliably determine the server's fully qualified domain name」のエラーは出る。
ただし、エラーメッセージの一部が変わった。
「using 127.0.0.1 for ServerName」の部分が
「using test.centos6 for ServerName」に変わった。
エラーメッセージの意味としては、
「サーバのfully qualified domain name(完全修飾ドメイン名:FQDN)を確実に決めることができなかったので、test.centos6をServerNameとして使用しています」
といったことだろうから、ApacheにServerNameを推測させるのではなく、ServerNameを明示的に設定すれば、エラーは消えるかな、と考える。
ふと思って、http.conf内のServerNameに関連する設定記述を見ると、以下のようなことが書かれている。
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
「This can often be determined automatically, but we recommend you specify it explicitly to prevent problems during startup.」のメッセージの意味としては、
「ServerNameは、しばしば自動的に決定されることがありますが、起動時の問題を防止するためにServerNameは明示的に指定することをお勧めします」ということだから、ServerNameを明示的に指定しないとApache起動時に問題が発生することが分かる。
[root@test ~]# vi /etc/httpd/conf/httpd.conf ←httpd.confを編集する。
#ServerName www.example.com:80
↓↓↓
ServerName test.centos6:80 ← ServerNameにホスト名、ポート番号を明示する。
[root@test ~]# /etc/rc.d/init.d/httpd restart ←Apache再起動。
httpd を停止中: [ OK ]
httpd を起動中: [ OK ]
エラーが解消された。
これで問題は解決した。
ServerNameは、今後はできる限り、明示的に設定しようと思った。