開発者ドキュメント

VPSで無料の署名付きSSL証明書を使用してApacheを設定する方法

注:以下の StartSSL.com プロセスの代わりに、Let’sEncryptの使用を検討することをお勧めします。 Let’s Encryptは、ほとんどのWebブラウザーで信頼されるSSL/TLS証明書を作成する無料および簡単の方法を提供する新しい認証局です。 チュートリアルをチェックして開始してください: Ubuntu14.04でLet’sEncryptを使用してApacheを保護する方法

前提条件

始める前に、このチュートリアルに必要なWebツールは次のとおりです。

<ol>
    <li><a href="https://www.google.com/intl/en/chrome/browser">Google Chrome</a> browser</li>
    <li>Apache installed on your VPS (cloud server)</li>
    <li>A domain name you own</li>
    <li>Access to an email address at that domain, either:
        <ol>
            <li>postmaster@duable.co</li>
            <li>hostmaster@duable.co</li>
            <li>webmaster@duable.co</li>
        </ol>
    </li>
</ol>

StartSSL.com は、完全に無料の確認済みを提供します(ユーザーは、「このサイトは信頼されていません」という恐ろしい赤い画面を見る必要がなくなります)で使用できるSSL証明書あなたのウェブサイト。 ほとんどの企業が同様のサービスに50ドルから60ドルを請求するため、これは大変なことです。 無料版は設定が少し難しいですが、それだけの価値はあります。

開始するには、 StartSSL.com にアクセスし、左側のツールバーを使用して、StartSSL Productsに移動し、次にStartSSL™Freeに移動します。 ページ上部からコントロールパネルのリンクを選択してください。

GoogleChromeを使用していることを確認してください

<ol>
    <li>Choose the <strong>Express Signup.</strong> option</li>
    <li>Enter your personal information, and click continue.</li>
    <li>You'll get an email with a verification code inside it shortly. Copy and paste that email into the form on StartSSL's page.</li>
    <li>They will review your request for a certificate and then send you an email with the new info. This process might take as long as 6 hours though, so be patient.</li>
    <li>Once the email comes, use the link provided and the new authentication code (at the bottom of the email) to continue to the next step.</li>
    <li>They will ask you to Generate a private key and you will be provided with the choice of "High" or "Medium" grade. Go ahead and choose "High".</li>
    <li>Once your key is ready, click Install.</li>
    <li>Chrome will show a popdown that says that the certificate has been succesfully installed to Chrome.</li>
</ol>


<p>This means your browser is now authenticated with your new certificate
and you can log into the StartSSL authentication areas using your new
certificate. Now, we need to get a properly formatted certificate set up for
use on your VPS. Click on the <a
href="https://www.startssl.com/?app=12">Control panel</a> link again, and
choose the Authenticate option. Chrome will show a popup asking if you want
to authenticate and will show the certificate you just installed. Go ahead
and authenticate with that certificate to enter the control panel.</p>

<p>You will need to validate your domain name to prove that you own the
domain you are setting up a certificate for. Click over to the Validations
Wizard in the <a href="https://www.startssl.com/?app=12">Control panel</a>
and set Type to Domain Name Validation. You'll be prompted to choose
from an email at your domain, something like postmaster@yourdomain.com.</p>

選択したメールアドレスのメール受信ボックスを確認してください。 そのアドレスにさらに別の確認メールが届くので、前と同じように、確認コードをコピーしてStartSSLWebサイトに貼り付けます。

次に、[証明書ウィザード]タブに移動し、WebサーバーのSSL/TLS証明書の作成を選択します。

[続行]をクリックしてから、他の設定をそのままにして、安全なパスワードを入力します。

秘密鍵を含むテキストボックスが表示されます。 内容をコピーしてテキストエディタに貼り付け、データをssl.keyというファイルに保存します。

[続行]をクリックすると、証明書を作成するドメインを尋ねられます。

ドメインを選択して、次の手順に進みます。

証明書を作成するサブドメインを尋ねられます。 ほとんどの場合、ここでwwwを選択しますが、SSLで別のサブドメインを使用する場合は、代わりにここに入力します。

StartSSLは、秘密鍵の場合と同じように、テキストボックスに新しい証明書を提供します。

ここでも、コピーしてテキストエディタに貼り付けます。今回は、ssl.crtとして保存します。

ただし、Webサイトを認証するには、StartComルートCAとStartSSLのクラス1中間サーバーCAも必要になるため、最後の手順として、[ツールボックス]ペインに移動し、[StartComCA証明書]を選択します。

この画面で、右クリックして2つのファイルとして保存します。

<ul>
    <li>StartCom Root CA (PEM Encoded) (save to ca.pem)</li>
    <li>Class 1 Intermediate Server CA (save to sub.class1.server.ca.pem)</li>
</ul>

セキュリティ上の理由から、StartSSLは秘密鍵(ssl.keyファイル)を暗号化しますが、Webサーバーは、サイトの暗号化を処理するために、暗号化されていないバージョンの秘密鍵を必要とします。 暗号化を解除するには、サーバーにコピーし、次のコマンドを使用してファイルprivate.keyに復号化します。

openssl rsa -in ssl.key -out private.key

OpenSSLはパスワードの入力を求めてくるので、StartSSLのWebサイトで入力したパスワードにパスワードを入力します。

この時点で、5つのファイルが必要です。 不足している場合は、前の手順を再確認して、再ダウンロードしてください。

<ul>
    <li>ca.pem - StartSSL's Root certificate</li>
    <li>private.key - The unencrypted version of your private key (be very careful no one else has access to this file!)</li>
    <li>sub.class1.server.ca.pem - The intermediate certificate for StartSSL</li>
    <li>ssl.key - The encrypted version of your private key (does not need to be copied to server)</li>
    <li>ssl.crt - Your new certificate</li>
</ul>

ssl.keyファイルを破棄できます。 他のサーバーをまだコピーしていない場合は、ここでアップロードします。

scp {ca.pem,private.key,sub.class1.server.ca.pem,ssl.crt} YOURSERVER:~ 
<h2>Activating the certificate in Apache</h2>

証明書を実際に使用できない場合、証明書を持っていることは何の役にも立ちません。 このセクションでは、新しいSSL証明書を使用するようにApacheを設定する方法について説明します。 これらの手順は、UbuntuVPSの最近のバージョンで実行されているApacheを対象としています。 他のLinuxベースのディストリビューションまたはWebサーバーの場合は、それに応じて調整する必要があります。

まず、キーを保存するフォルダーを作成します。 ApacheのSSLモジュールを有効にして、Apacheを再起動します。

sudo a2enmod ssl
sudo service apache2 restart
sudo mkdir -p /etc/apache2/ssl

前のセクションで設定したファイルをVPSの/etc/ apache2/sslフォルダーにコピーします。

sudo mkdir -p /etc/apache2/ssl
cp ~/{ca.pem,private.key,sub.class1.server.ca.pem,ssl.crt} /etc/apache2/ssl

実行する:

ls /etc/apache2/ssl

そしてそれは戻るはずです:

ca.pem
ssl.crt
private.key
sub.class1.server.ca.pem

次に、apache2構成ファイルを開きます。 デフォルト設定をすでに変更していない限り、次のように入力します。

nano /etc/apache2/sites-enabled/000-default

次のようになります。

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

上記のスクリプト全体をコピーします(からに )、既存のものの下に貼り付けて、一番上の行を次のように変更します。

<VirtualHost *:80>

<VirtualHost *:443>

そして、の後に次の行を追加しますライン:

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

SSLCertificateFile /etc/apache2/ssl/ssl.crt                           
SSLCertificateKeyFile /etc/apache2/ssl/private.key                        
SSLCertificateChainFile /etc/apache2/ssl/sub.class1.server.ca.pem 

最終結果は次のようになります。

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

<VirtualHost *:443>
    SSLEngine on                                                                
    SSLProtocol all -SSLv2                                                      
    SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM                

    SSLCertificateFile /etc/apache2/ssl/ssl.crt                           
    SSLCertificateKeyFile /etc/apache2/ssl/private.key                        
    SSLCertificateChainFile /etc/apache2/ssl/sub.class1.server.ca.pem 
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

ファイルを保存し、次のコマンドでApacheを再起動します。

sudo service apache2 restart

Apacheのログファイルをチェックして、次のコマンドでshowstoppingエラーが発生していないかどうかを確認できます。

cat /var/log/apache2/error.log

すべてが良好に見える場合は、HTTPS URLを使用してWebブラウザでサイトにアクセスしてみてください(例: https ://www.YOURSITE.com)。 サイトが読み込まれると、URLの横に小さな緑色の錠前アイコンが表示されます。 それをクリックすると、次のように表示されます。 [接続]タブには、サイトのIDがStartComによって確認されたことが表示されます。

おめでとう! 準備万端です!

<p>Reference Links:</p>

これをまとめるときに私が参考にした他の投稿のいくつかを次に示します。 問題が発生した場合、それらを修正する方法についてのインスピレーションの源となる可能性があります。

<ul>
    <li><a href="http://www.debian-administration.org/articles/349">Apache SSL Configuration</a></li>
    <li><a href="http://jasoncodes.com/posts/startssl-free-ssl">StartSSL Apache Guides</a></li>
</ul>
投稿者:Nik van der Ploeg
モバイルバージョンを終了