httpdのSSL対応

準備


ツールのインストール先
httpd c:\Opt\Apache
openssl C:\OpenSSL-Win64

証明書を作成するのでopensslをインストールする
http://slproweb.com/products/Win32OpenSSL.html
Win64OpenSSL-1_0_1h.exe

環境変数の設定
変数名 変数値
追記 Path C:\Opt\Apache\bin;C:\OpenSSL-Win64\bin;
新規 OPENSSL_CONF C:\Opt\Apache\conf\openssl.cnf

レジストリを修正
regedit(管理者権限有)の起動し、以下の内容を変更する
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Apache2.2\ImagePath

C:\Opt\apache\bin\httpd.exe -k runservice
を
C:\Opt\apache\bin\httpd.exe -D SSL -k runservice

設定確認
コマンドプロンプトを起動する
> openssl version
OpenSSL 0.9.8y 5 Feb 2013

> httpd -v
Server version: Apache/2.2.25 (Win32)
Server built:   Jul 10 2013 01:52:12

サーバ証明書を作成する

コマンドプロンプト(管理者有)を起動する
オレオレ証明書の場合は-des3を消して実行

手順1
C:\> cd C:\Opt\Apache\conf
C:\Opt\apache\conf>openssl genrsa -des3 -out server.key 2048
Loading 'screen' into random state - done
Generating RSA private key, 2048 bit long modulus
...........+++
..........................................................+++
e is 65537 (0x10001)
Enter pass phrase for server.key:パスワード
Verifying - Enter pass phrase for server.key:パスワード

手順2
C:\Opt\apache\conf>openssl req -new -key server.key -out server.csr
Enter pass phrase for server.key:パスワード
Loading 'screen' into random state - done
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) [AU]:
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:ホスト名
Email Address []:

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

以下は説明
Country Name※ 国を示す2文字のISO略語です。 JP
State or Province Name※ 組織が置かれている都道府県です。 Osaka
Locality Name※ 組織が置かれている市区町村です。 Osaka-shi
Organization Name※ 組織の名称です。 GlobalSign K.K.
Organization Unit Name "組織での部署名です。※指定がない場合は - (ハイフン)を入力してください。 Sales
Common Name※ ウェブサーバのFQDNです。 ssl.globalsign.com
Email Address 入力不要です。 -
A challenge password 入力不要です。 -
An optional company name 入力不要です。 -

手順3
正式の証明書の場合は、ベルサインなどに依頼するらしいが、オレオレの場合は以下を実行する

C:\Opt\apache\conf>openssl x509 -days 3650 -req -signkey server.key < server.csr > server.crt
Loading 'screen' into random state - done
Signature ok
subject=/C=AU/ST=Some-State/O=Internet Widgits Pty Ltd/CN=ホスト名
Getting Private key
Enter pass phrase for server.key:パスワード

httpd.confの編集


C:\Opt\Apache\conf\httpd.conf

#LoadModule ssl_module modules/mod_ssl.so
↓
LoadModule ssl_module modules/mod_ssl.so

#Include conf/extra/httpd-ssl.conf
↓
Include conf/extra/httpd-ssl.conf

C:\Opt\apache\conf\extra\httpd-ssl.conf

#SSLCertificateFile "C:/Opt/apache/conf/server.crt"
↓
SSLCertificateFile "C:/Opt/apache/conf/server.crt"

#SSLCertificateKeyFile "C:/Opt/apache/conf/server.key"
↓
SSLCertificateKeyFile "C:/Opt/apache/conf/server.key"

SSLPassPhraseDialog  builtin
↓
SSLPassPhraseDialog exec:conf/passphrase.bat

C:\Opt\apache\conf\passphrase.bat(なければ作成する。中身はopensslで設定したパスワード)

echo パスワード

設定が完了後、ApacheのConfigurationをテスト
すべてのプログラム >> Apache HTTP Server 2.x.x >> Configure Apache Server >> Test Configuration

エラーがある場合は設定ファイルの該当箇所を修正します

SSLMutexのエラーが出る場合は、該当箇所をコメントアウト(行頭に#を記載)します

# SSLMutex "file:C:/Program Files/Apache Software Foundation/Apache2.2/logs/ssl_mutex"

設定後サーバを再起動し、ブラウザで「https://localhost」に接続してみる


このサイトのセキュリティ証明書は信頼できません
と表示されればOKで「このまま続行」ボタンをクリックして、「It works!」と出れば完了

2014/7/22
最終更新:2014年08月04日 16:22