前回はUbuntu14.04(Nginx)にRapidSSLを導入しましたを書きました。ただ、Apache2の場合であれば、若干設定が違うのでApache2の場合の記事も書きたいと思っています。前半の手順(証明書発行)は前回の記事と同じ内容となりますが〜
環境はUbuntu14.04(Apache2)での手順ですが、どのOSでも大抵一緒だと思います。前提はOpenSSLを使うことになりますが〜
サーバーにログインし、ルート権限になってください。
まずは、秘密キーを発行します。
mkdir /etc/nginx/ssl cd /etc/nginx/ssl/ openssl genrsa -des3 -out server.key 2048
それからCSRファイルを発行します。これはSSL証明書を買う時には必要な内容です。
openssl req -new -key server.key -out server.csr
Enter pass phrase for server.key: {秘密キー入力}
Country Name (2 letter code) [XX]:{JP}
State or Province Name (full name) []:{Saitama}
Locality Name (eg, city) [Default City]:{Saitama-City}
Organization Name (eg, company) [Default Company Ltd]:{Co-mit Inc.}
Organizational Unit Name (eg, section) []:{Development}
Common Name (eg, your name or your server's hostname) []:{*.co-mit.com}
Email Address []:{管理アドレスメールを入れる}
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:{何もしないでenter}
An optional company name []:{何もしないでenter}
ワイルドカードタイプで大事なのはCommon Nameです。ここは*.co-mit.comのように入力しないといけません。そうすると、sub1.co-mit.com、sub2.co-mit.comは使えます。
cat server.csrコマンドでその内容をコピーしてください。
RapidSSLといってもいろいろなところで買えます。一番安いssl-store.jpで買いました。
ECサイトで買い物する感覚でSSL証明書を購入してください。ssl-store.jpはオンラインサイトですので、即にSSL証明書を発行してくれるのでうれしいです。先ほど作成されたCSRファイル内容の貼り付けがあります。
すると、SSL証明書内容が書かれるメールを受信できると購入完了です。
RapidSSLの場合、サーバー証明書と中間証明書の2つがあります。
サーバー証明書の内容:
-----BEGIN CERTIFICATE----- サーバ証明書のxxxxx -----END CERTIFICATE-----
サーバー中間証明書の内容:
-----BEGIN CERTIFICATE----- 中間証明書のxxxxx -----END CERTIFICATE-----
それぞれサーバー証明書はserver.pem、サーバー中間証明書はserver-chain.crtに保存してください。
これはめんどくさいので、特にサーバー再起動は大変です。なので、パスフレーズを聞かないようにしたほうがいいです。
cp server.key server.key.withpass openssl rsa -in server.key -out server.key
後はApache2の設定をやれば終わりです。弊社の設定だとこんな感じ。
# Enable/Disable SSL for this virtual host.
SSLEngine on
# A self-signed (snakeoil) certificate can be created by installing
# the ssl-cert package. See
# /usr/share/doc/apache2/README.Debian.gz for more info.
# If both key and certificate are stored in the same file, only the
# SSLCertificateFile directive is needed.
SSLCertificateFile /etc/apache2/ssl/server.pem
SSLCertificateKeyFile /etc/apache2/ssl/server.key
# Server Certificate Chain:
# Point SSLCertificateChainFile at a file containing the
# concatenation of PEM encoded CA certificates which form the
# certificate chain for the server certificate. Alternatively
# the referenced file can be the same as SSLCertificateFile
# when the CA certificates are directly appended to the server
# certificate for convinience.
SSLCertificateChainFile /etc/apache2/ssl/server-chain.crt
Apacheの場合は、サーバー証明書ファイルと中間証明書ファイルを分けないといけません。それとは違ってNginxの場合はサーバー証明書と中間証明書を1つのサーバー証明書にまとめています。その後、Apache2を再起動して、httpsでアクセス問題なければ終わりです。ブラウザーではこんな感じです。

Leave a Comment