edo1z blog

プログラミングなどに関するブログです

さくらVPS CentOS6.5でSSLをつかってみる

さくらサーバでSSLつかってみましょう。環境は下記になります。

・FreeBSD 9.1-RELEASE-p7 amd64 ・さくらのレンタルサーバ スタンダード ・Apache/2.2.25

あら独自SSLを使えるのは、ビジネスプロ以降らしい。http://www.sakura.ne.jp/ では、VPSを使ってやってみよう。環境は下記になります。

・CentOS release 6.5 (Final) ・Apache/2.2.15 (Unix) ・OpenSSL 1.0.1e-fips 11 Feb 2013

mod_sslをインストールする

$ yum -y install mod_ssl

mod_ssl.x86_64 1:2.2.15-29.el6.centosというのがインストールされた。

CA用秘密鍵(ca.key)の作成

$ openssl genrsa -des3 -out /etc/httpd/conf/ca.key -rand rand.dat 1024

CA用証明書(ca.crt)の作成

$ openssl req -new -x509 -days 365 -key /etc/httpd/conf/ca.key -out /etc/httpd/conf/ca.crt

サーバ用秘密鍵(server.key)の作成

$ openssl genrsa -des3 -out /etc/httpd/conf/server.key -rand rand.dat 1024

署名要求書(server.csr)の作成

$ openssl req -new -key /etc/httpd/conf/server.key -out /etc/httpd/conf/server.csr

サーバ用秘密鍵(server.key)からのパスフレーズ削除

オリジナルをバックアップしてから、server.keyからのパスフレーズ削除

$ cp /etc/httpd/conf/server.key /etc/httpd/conf/server.key.bak
$ openssl rsa -in /etc/httpd/conf/server.key.bak -out /etc/httpd/conf/server.key

サーバ用証明書(server.crt)の作成

$ openssl x509 -req -signkey /etc/httpd/conf/server.key -days 3650 -in /etc/httpd/conf/server.csr -out /etc/httpd/conf/server.crt

ssl設定ファイル(ssl.conf)の変更

$ vim /etc/httpd/conf.d/ssl.conf

100 #   Server Certificate:
101 # Point SSLCertificateFile at a PEM encoded certificate.  If
102 # the certificate is encrypted, then you will be prompted for a
103 # pass phrase.  Note that a kill -HUP will prompt again.  A new
104 # certificate can be generated using the genkey(1) command.
105
106 #SSLCertificateFile /etc/pki/tls/certs/localhost.crt
107 SSLCertificateFile /etc/httpd/conf/server.crt #<--これに変更
108
109 #   Server Private Key:
110 #   If the key is not combined with the certificate, use this
111 #   directive to point at the key file.  Keep in mind that if
112 #   you've both a RSA and a DSA private key you can configure
113 #   both in parallel (to also allow the use of DSA ciphers, etc.)
114
115 #SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
116 SSLCertificateKeyFile /etc/httpd/conf/server.key #<--これに変更

Apache再起動

/etc/rc.d/init.d/httpd restart

これでhttpsでアクセスすると反映されてた。

参考:はじめての自宅サーバ構築 - Fedora/CentOS -