2011年2月13日日曜日

CentOS 5.5でhttpd + SSLを設定時の落とし穴

サーバ管理の目的(phpmyadmin, webminなど)でSSLが必要になったが、そのためにSSL証明書を買うのは馬鹿馬鹿しい。そこで自作の証明書(self-signed certificate)を作って使うことにした。証明書の作り方はここに説明がある。

http://www.akadia.com/services/ssh_test_certificate.html

CentOSでの証明書のインストール方法はここを参照した。

http://www.centos.org/docs/5/html/Deployment_Guide-en-US/s1-httpd-secure-server.html

これですんなりいくはずだったが、ブラウザはタイムアウトばかりで一向につながらない。OpenSSLのs_clientコマンドではつながるのに。そこで思いついたのはファイアーウォール(iptables)の設定。何とCentOSのデフォルトでは443番ポートはクローズでした。そこで次のコマンドでポートを開いたら、すべて動き出しました。

iptables -I INPUT -p tcp -m state --state NEW,ESTABLISHED --dport 443 -j ACCEPT

Configure httpd with SSL on CentOS 5.5

I needed web SSL support for private server-admin purposes, i.e. phpmyadmin and webmin. It'd be silly to pay for an SSL certificate just for that. This site explains how to create a self-signed certificate.

http://www.akadia.com/services/ssh_test_certificate.html

Certificate installation instructions for CentOS are here:

http://www.centos.org/docs/5/html/Deployment_Guide-en-US/s1-httpd-secure-server.html

I followed the instructions found at these sites, but my server kept giving me timeout errors despite the fact that I could connect to the secure site through OpenSSL's s_client command. Then, it occurred to me that I should check my firewall (iptables) setting. That was it! CentOS's default is port 443=closed. I opened it with this command, and everything started working.

iptables -I INPUT -p tcp -m state --state NEW,ESTABLISHED --dport 443 -j ACCEPT