Ubuntu10.10 自宅サーバ構築手順:WebサーバSSL通信対応(SSL)

Apache2導入済である事を前提とします。


absj31@absj31-MyHomeServer:~$ cd /etc/apache2
absj31@absj31-MyHomeServer:/etc/apache2$ sudo mkdir ssl
absj31@absj31-MyHomeServer:/etc/apache2$ cd ssl/
absj31@absj31-MyHomeServer:/etc/apache2/ssl$ sudo openssl genrsa -des3 1024 > server.key
Generating RSA private key, 1024 bit long modulus
........................................++++++
.........++++++
e is 65537 (0x10001)
Enter pass phrase: (任意のパスフレーズを入力)
Verifying - Enter pass phrase: (任意のパスフレーズを再度入力)
absj31@absj31-MyHomeServer:/etc/apache2/ssl$ 
  • CSRファイルを作成。
absj31@absj31-MyHomeServer:/etc/apache2/ssl$ sudo openssl req -new -key server.key > server.csr
Enter pass phrase for server.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.
-----
(※以降、情報入力を幾つか求められる。任意の情報を入力orEnterキー押下でデフォルト入力を行い、先へ進む)
  • 自己証明書を作成。
absj31@absj31-MyHomeServer:/etc/apache2/ssl$ sudo openssl x509 -in server.csr -days 365 -req -signkey server.key > server.crt
Signature ok
subject=/C=JP/...
Getting Private key
Enter pass phrase for server.key: (上記で設定したパスフレーズを入力)
absj31@absj31-MyHomeServer:/etc/apache2/ssl$ 
  • SSLを有効化。
absj31@absj31-MyHomeServer:/etc/apache2/ssl$ sudo a2enmod ssl
Enabling module ssl.
See /usr/share/doc/apache2.2-common/README.Debian.gz on how to configure SSL and create self-signed certificates.
Run '/etc/init.d/apache2 restart' to activate new configuration!
absj31@absj31-MyHomeServer:/etc/apache2/ssl$ 
  • SSL用のVirtualHostを作成。既存のファイルをコピーして編集する方法を採ってみる。
absj31@absj31-MyHomeServer:/etc/apache2/ssl$ sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/ssl

-----------------
<VirtualHost *:443>
        ServerAdmin webmaster@localhost
        SSLCertificateFile      /etc/apache2/ssl/server.crt
        SSLCertificateKeyFile   /etc/apache2/ssl/server.key
        ServerName server.domain:443
        SSLEngine on
        DocumentRoot /var/www
        <Directory />
        :
        :
absj31@absj31-MyHomeServer:/etc/apache2/ssl$ sudo a2ensite ssl
Enabling site ssl.
See /usr/share/doc/apache2.2-common/README.Debian.gz on how to configure SSL and create self-signed certificates.
Run '/etc/init.d/apache2 reload' to activate new configuration!
absj31@absj31-MyHomeServer:/etc/apache2/ssl$ sudo service apache2 restart
 * Restarting web server apache2
 ... waiting ..Apache/2.2.16 mod_ssl/2.2.16 (Pass Phrase Dialog)
Some of your private key files are encrypted for security reasons.
In order to read them you have to provide the pass phrases.

Server server.domain:443 (RSA)
Enter pass phrase: (設定したパスフレーズを入力)

OK: Pass Phrase Dialog successful.
                                                             [ OK ]
absj31@absj31-MyHomeServer:/etc/apache2/ssl$ 
  • SSLの確認を行う。サーバ内のブラウザ(ここではFirefox)を起動、https://localhost/ にアクセス。以下の内容が表示されるので[危険性を理解した上で接続するには]をクリック。

  • [例外を追加]ボタンを押下。

  • [セキュリティ例外を承認]ボタンを押下。

  • 接続完了。

  • 外部からの接続の場合は、ファイアウォール設定に『ポート:443』を追加し同様の手順で接続確認を行う。


参考URL: