LoginSignup
8

More than 5 years have passed since last update.

ComodoのSSL証明書をNginxにインストール

Last updated at Posted at 2016-02-29

ComodoのSSL証明書をApache+mod_sslにインストールのNginx版。

証明書の購入

*.domain.com と dmn.com の二種類必要だったので、Comodo EssentialSSL Wildcard と Comodo PositiveSSL を購入。
販売代理店私は当初 SSLs で申し込んだものの、後になって GoGetSSL の方が安い上に管理画面が充実している事が判明したため、 SSLs はキャンセル。SSLs はチャット、メールサポート共に対応は早い。
販売代理店はいくつか検討しましたが、低価格ながらもサイトの作りがしっかりしている販売代理店は以下の通り。
* GoGetSSL
* CheapSSLSecurity
* NameCheap
* SSLs

Comodo EssentialSSL Wildcard用の証明書の作成

秘密鍵の作成

shell
$ cd /etc/pki/tls/certs/
$ openssl req -nodes -newkey rsa:2048 -keyout domain.com.key -out domain.com.csr
Generating a 2048 bit RSA private key
.+++
.....+++
writing new private key to 'domain.com.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:JP
State or Province Name (full name) []:Tokyo
Locality Name (eg, city) [Default City]:Shibuya
Organization Name (eg, company) [Default Company Ltd]:Domain Company
Organizational Unit Name (eg, section) []:(Blank)
Common Name (eg, your name or your server's hostname) []:*.domain.com
Email Address []:admin@domain.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:(Blank)
An optional company name []:(Blank)

秘密鍵をアップロードし証明書を受け取る

  1. 生成した秘密鍵 (/etc/pki/tls/certs/domain.com.csr) の内容をコピーし、GoGetSSLの管理画面から送信。

  2. 諸々の手続き完了後、Comodoからバリデーション要求メールが送られてくる。指定のアドレスで認証を行うと、登録メールアドレスにZIPアーカイブが送られてくる。

認証完了後送られてくるメールに添付されているZIPアーカイブの内容。

ファイル名 種別
AddTrustExternalCARoot.crt ルート証明書
COMODORSAAddTrustCA.crt 中間証明書
COMODORSADomainValidationSecureServerCA.crt 中間証明書
STAR_domain_com.crt サーバ証明書

ZIPアーカイブのうち、3つのファイルを/etc/pki/tls/certs/domain.com.ca-bundle.crtにまとめる。

shell
$ cat STAR_domain_com.crt COMODORSADomainValidationSecureServerCA.crt COMODORSAAddTrustCA.crt >> domain.com.ca-bundle.crt

一連の作業で作成したファイルは以下の3つ。

shell
$ ls -l /etc/pki/tls/certs/
-rw-r--r--  1 root root    1704 Aug 23 16:46 domain.com.key
-rw-r--r--  1 root root    1033 Aug 23 16:46 domain.com.csr
-rw-r--r--  1 root root    5627 Aug 23 17:00 domain.com.ca-bundle.crt

DH鍵交換に使用するパラメータファイルを生成

/etc/nginx/nginx.conf
$ cd /etc/pki/tls/certs
$ openssl dhparam -out dhparam2048.pem 2048

Nginxの設定

/etc/nginx/nginx.conf
http {

    ...

    ssl_dhparam       /etc/pki/tls/certs/dhparam4096.pem;

    ...

    include /etc/nginx/sites-enabled/*.conf;
}
/etc/nginx/sites-enabled/vhost_domain.com.conf
server {
    listen 443 ssl;

    ...

    ssl on;
    ssl_certificate           /etc/pki/tls/certs/domain.com.ca-bundle.crt;
    ssl_certificate_key       /etc/pki/tls/certs/domain.com.key;
    ssl_session_timeout       5m;
    ssl_protocols             TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers               'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
    ssl_prefer_server_ciphers on;
    ssl_session_cache         builtin:1000 shared:SSL:10m;
    add_header                Strict-Transport-Security 'max-age=31536000; includeSubDomains;';

    ...

}

SSLの安全性を確認

Qualys SSL LABS - SSL Server TestでSSLの安全性を確認。

SSLTest.jpg

Comodo PositiveSSL用の証明書の作成

  • Comodo EssentialSSL Wildcard用の証明書の作成と手順は同じ。domain.com を dmn.com に置き換えるだけ。
  • 秘密鍵生成の際は、間違えてホスト名にワイルドカード指定しないこと。
shell
Common Name (eg, your name or your server's hostname) []:dmn.com

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
8