SSL 証明書発行
特定ドメインにてhttps(443)アクセスを可能にしたい場合のApache設定手順
1. mod_sslの確認とインストール
mod_sslがインストールされているかを確認
何も表示されない場合には mod_ssl のインストールを実行
インストール後、ssl.conf ファイルの存在を確認
ll /etc/httpd/conf.d/
-rw-r--r--. 1 root root 392 8月 14 02:30 2013 README
-rw-r--r--. 1 root root 990 3月 6 00:09 2014 php.conf
-rw-r--r-- 1 root root 9473 8月 2 20:59 2013 ssl.conf
-rw-r--r--. 1 root root 299 8月 2 20:59 2013 welcome.conf
1. keyファイル作成
cd ssl/
keyファイル作成
openssl genrsa -des3 2048 > hogehoge.co.jp.key
Enter pass phrase: (パスフレーズ入力)
Verifying - Enter pass phrase: (パスフレーズ入力)
パスフレーズ解除
openssl rsa -in hogehoge.co.jp.key -out hogehoge.co.jp.key
Enter pass phrase for hogehoge.co.jp.key:(パスフレーズ入力)
writing RSA key
2. csrファイル作成
csrファイル作成
openssl req -new -key hogehoge.co.jp.key -out hogehoge.co.jp.csr
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]:Bunkyo
Organization Name (eg, company) [Default Company Ltd]:hoge Inc.
Organizational Unit Name (eg, section) :
Common Name (eg, your name or your server's hostname) :hogehoge.co.jp
Email Address :
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password :
An optional company name :
3. crtファイル作成
openssl x509 -req -in hogehoge.co.jp.csr -signkey hogehoge.co.jp.key -out hogehoge.co.jp.crt
Signature ok
subject=/C=JP/ST=Tokyo/L=Bunkyo/O=hogehoge.co.jp Inc./CN=hogehoge.co.jp
Getting Private key
4. Apache confファイル作成
vim /etc/httpd/conf.d/hogehoge.co.jp.conf
<VirtualHost *:443>
ServerName hogehoge.co.jp:443
DocumentRoot "/var/www/html/hogehoge.co.jp/htdocs"
ErrorLog logs/hogehoge.co.jp-ssl_error.log
TransferLog logs/hogehoge.co.jp-ssl_access.log
LogLevel warn
SSLEngine on
SSLProtocol all -SSLv2
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
SSLCertificateFile /etc/httpd/ssl/hogehoge.co.jp.crt
SSLCertificateKeyFile /etc/httpd/ssl/hogehoge.co.jp.key
<Files ~ "\.(cgi|shtml|phtml|php3?)$">
SSLOptions +StdEnvVars
</Files>
<Directory "/var/www/cgi-bin">
SSLOptions +StdEnvVars
</Directory>
SetEnvIf User-Agent ".*MSIE.*" \
nokeepalive ssl-unclean-shutdown \ downgrade-1.0 force-response-1.0
CustomLog logs/ssl_request_log \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>
5. iptables 443ポート解放
-A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
service iptables restart
iptables: チェインをポリシー ACCEPT へ設定中filter [ OK ]
iptables: ファイアウォールルールを消去中: [ OK ]
iptables: モジュールを取り外し中: [ OK ]
iptables: ファイアウォールルールを適用中: [ OK ]
443 ポートが解放された事を確認
netstat -lntp
6. Apache 再起動
service httpd configtest
service httpd restart
7. KEYの確認
openssl rsa -text -noout -in hogehoge.co.jp.key
7. CSRの確認
openssl req -text -noout -in hogehoge.co.jp.csr
9. CRTの確認
openssl x509 -text -noout -in hogehoge.co.jp.crt