LoginSignup
3
2

More than 5 years have passed since last update.

さくらVPS(Cent OS6 Apache)でKING SSLを設定する

Last updated at Posted at 2017-03-04

KingSSL公式の手順書を参考にしたんですが途中ではまったので解決した手順を書きます。
※今回はワイルドカードSSLを契約しています。
こちらがかなり参考になりました。

1.CSR生成とSSL申請

  • CSR生成

コチラを参考にしてCSRを生成してください。
ワイルドカードの場合、Common Nameにアスタリスク[*]を含めてください。
例: *.kingssl.com

  • SSL申請 KingSSLの以下申請画面に上記で作成したCSRを貼り付けて申請を行って下さい。 csr.png

2.証明書をサーバーに保存

申込者の元へ「[KingSSL]サーバ証明書発行のお知らせ」というメールが届きますのでそちらをサーバー(VPS)に保存します。
Apacheのディレクトリに「ssl.crt」というフォルダを作成してください。
sudo mkdir /etc/httpd/conf/ssl.crt

KingSSLから送られてきた「証明書」と「中間証明書」を作成します。
※「xxxx」はなんでもOKです。統一名で保存しておくと管理しやすいと思います。
1.「証明書」
sudo vi /etc/httpd/conf/ssl.crt/xxxx.crt
※ここに証明書を貼り付けてください。

2.「中間証明書」
sudo vi /etc/httpd/conf/ssl.crt/xxxx.cer
※ここに中間証明書を貼り付けてください。

3.ssl.confを編集する

※念のためバックアップを取得しておいてください。
sudo cp /etc/httpd/conf.d/ssl.conf /etc/httpd/conf.d/ssl.conf_back

  • 以降をザックリ全部削除します。
    (後で別ファイルでVirtualHostを設定します。)
  • SNIに未対応のブラウザ対策として、以下の一行を追加します。
    SSLStrictSNIVHostCheck off
  • 名前ベースのバーチャルホストを使用できるように宣言します。
    NameVirtualHost *:443

※恐れず以下のようにガッツリと以下を消しちゃって下さい。
※修正後以下のようになっていればOKです

qiita.conf
# This is the Apache server configuration file providing SSL support.
# It contains the configuration directives to instruct the server how to
# serve pages over an https connection. For detailing information about these 
# directives see <URL:http://httpd.apache.org/docs/2.2/mod/mod_ssl.html>
# 
# Do NOT simply read the instructions in here without understanding
# what they do.  They're here only as hints or reminders.  If you are unsure
# consult the online docs. You have been warned.  
#

LoadModule ssl_module modules/mod_ssl.so

#
# When we also provide SSL we have to listen to the 
# the HTTPS port in addition.
#
Listen 443

##
##  SSL Global Context
##
##  All SSL configuration in this context applies both to
##  the main server and all SSL-enabled virtual hosts.
##

#   Pass Phrase Dialog:
#   Configure the pass phrase gathering process.
#   The filtering dialog program (`builtin' is a internal
#   terminal dialog) has to provide the pass phrase on stdout.
SSLPassPhraseDialog  builtin
#SSLPassPhraseDialog exec:/etc/httpd/conf.d/pass-phrase.sh

#   Inter-Process Session Cache:
#   Configure the SSL Session Cache: First the mechanism 
#   to use and second the expiring timeout (in seconds).
SSLSessionCache         shmcb:/var/cache/mod_ssl/scache(512000)
SSLSessionCacheTimeout  300

#   Semaphore:
#   Configure the path to the mutual exclusion semaphore the
#   SSL engine uses internally for inter-process synchronization. 
SSLMutex default

#   Pseudo Random Number Generator (PRNG):
#   Configure one or more sources to seed the PRNG of the 
#   SSL library. The seed data should be of good random quality.
#   WARNING! On some platforms /dev/random blocks if not enough entropy
#   is available. This means you then cannot use the /dev/random device
#   because it would lead to very long connection times (as long as
#   it requires to make more entropy available). But usually those
#   platforms additionally provide a /dev/urandom device which doesn't
#   block. So, if available, use this one instead. Read the mod_ssl User
#   Manual for more details.
SSLRandomSeed startup file:/dev/urandom  256
SSLRandomSeed connect builtin
#SSLRandomSeed startup file:/dev/random  512
#SSLRandomSeed connect file:/dev/random  512
#SSLRandomSeed connect file:/dev/urandom 512

#
# Use "SSLCryptoDevice" to enable any supported hardware
# accelerators. Use "openssl engine -v" to list supported
# engine names.  NOTE: If you enable an accelerator and the
# server does not start, consult the error logs and ensure
# your accelerator is functioning properly. 
#
SSLCryptoDevice builtin
#SSLCryptoDevice ubsec


# offに設定(SNIに未対応のブラウザ用)
SSLStrictSNIVHostCheck off

NameVirtualHost *:443

4.バーチャルホスト設定ファイルを編集する

/etc/httpd/conf.d/vhost.conf(名前はご自由に)を編集します。
以下内容を記述します。

qiita.conf
NameVirtualHost IPアドレス:443
<VirtualHost IPアドレス:443>
    ServerName ドメイン名(test.com)
    ServerAlias www.test.com

    DocumentRoot /var/www/html(必要に応じて変更)

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^(www\.test\.com) [NC]
    RewriteRule ^/(.*) https://test.com/$1 [R=301,L]

    ErrorLog logs/error_log
    CustomLog logs/access_log combined

    SSLEngine on

    SSLCertificateChainFile /etc/httpd/conf/ssl.crt/xxxx.cer(2で作成した中間証明書)
    SSLCertificateFile      /etc/httpd/conf/ssl.crt/xxxx.crt(2で作成した証明書)
    SSLCertificateKeyFile   /etc/httpd/conf/ssl.csr/xxxx.key(1で作成している秘密鍵

    SSLProtocol             all -SSLv2 -SSLv3
    SSLCipherSuite          ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
    SSLHonorCipherOrder     on

    <Directory "/var/www/html">
        DirectoryIndex index.html index.htm index.php index.cgi index.html.var
        Options -Indexes ExecCGI FollowSymLinks
        AllowOverride All
      #mod_deflate設定
      <IfModule mod_deflate.c>
        SetOutputFilter DEFLATE
        AddOutputFilterByType DEFLATE text/html text/plain text/xhogehogeml application/x-javascript text/css
      </IfModule>
        Order deny,allow
        Allow from all
    </Directory>
    SetEnvIf User-Agent ".*MSIE.*" \
         nokeepalive ssl-unclean-shutdown \
         downgrade-1.0 force-response-1.0
</VirtualHost>
<VirtualHost>
 サブドメインが必要な場合、上記内容をコピペし、servernameにサブドメインを付ける
</VirtualHost>

※Apachのバージョンや、opensslのバージョンによって上記設定が変わってくるので、こちらのジェネレーターを使うと便利です。

5.Apacheを再起動

apachectl stop
apachectl start
※SSL証明書のパスフレーズの入力を求められますので、秘密鍵を作った時のパスワードを入力します。

3
2
0

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
3
2