概要
- Apacheとmod_sslをつかって、httpsを使えるようにする
環境
- OS:CentSO /Redhat 6.x
- httpd/mod_ssl:2.2.x
手順
Apacheとmod_sslをインストール
# yum install -y httpd mod_ssl
# chkconfig httpd on
ブラウザアクセスし、Apacheの画面が表示されることを確認
秘密鍵 (Private Key)、サーバ証明書(CRT)を配置する
- 秘密鍵 (Private Key):server.key
- サーバ証明書(CRT):server.crt
# ls /etc/httpd/conf/ssl.key/
server.key
# ls /etc/httpd/conf/ssl.crt/
server.crt
ssl.confを編集する
- 秘密鍵、サーバ証明書のファイル名、配置場所を修正する
/etc/httpd/conf.d/ssl.conf
# SSLCertificateFileを実際の配置場所にあわせる
SSLCertificateFile /etc/httpd/conf/ssl.crt/server.crt
# SSLCertificateKeyFileを実際の配置場所にあわせる
SSLCertificateKeyFile /etc/httpd/conf/ssl.key/server.key
```
### rewrite.confを編集する
* httpリクエストが来た際、httpsリクエストへリダイレクトさせる
````bash:/etc/httpd/conf.d/rewrite.conf
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
</ifModule>
```
### Apache再起動
<pre>
# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
</pre>
### ブラウザアクセスし、https通信でApacheの画面が表示されることを確認
