웹사이트 검색

VPS에서 무료 서명 SSL 인증서로 Apache를 설정하는 방법


참고: Ubuntu 14.04에서 Let's Encrypt로 Apache를 보호하는 방법
대신 Let's Encrypt 사용을 고려할 수 있습니다.

전제 조건

시작하기 전에 이 자습서에 필요한 웹 도구는 다음과 같습니다.

<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를 청구하기 때문에 이는 매우 좋은 거래입니다. 무료 버전은 설정하기가 약간 까다롭지만 그만한 가치가 있습니다.

시작하려면 페이지 상단에서 제어판으로 이동하십시오.

Google 크롬을 사용하고 있는지 확인하세요.

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

선택한 이메일 주소의 이메일 받은편지함을 확인하세요. 해당 주소로 또 다른 확인 이메일을 받게 되므로 이전과 마찬가지로 확인 코드를 복사하여 StartSSL 웹사이트에 붙여넣으십시오.

그런 다음 인증서 마법사 탭으로 이동하여 웹 서버 SSL/TLS 인증서 생성을 선택합니다.

계속을 누른 다음 보안 암호를 입력하고 다른 설정은 그대로 둡니다.

개인 키가 포함된 텍스트 상자가 표시됩니다. 내용을 복사하여 텍스트 편집기에 붙여넣고 데이터를 ssl.key라는 파일에 저장합니다.

계속을 클릭하면 인증서를 생성할 도메인을 묻는 메시지가 표시됩니다.

도메인을 선택하고 다음 단계로 진행합니다.

인증서를 생성하려는 하위 도메인을 묻는 메시지가 표시됩니다. 대부분의 경우 여기에서 www를 선택하고 싶지만 SSL과 함께 다른 하위 도메인을 사용하려면 대신 여기에 입력하십시오.

StartSSL은 개인 키와 마찬가지로 텍스트 상자에 새 인증서를 제공합니다.

다시 텍스트 편집기에 복사하여 붙여넣고 이번에는 ssl.crt로 저장합니다.

또한 웹 사이트를 인증하려면 StartCom 루트 CA 및 StartSSL 클래스 1 중간 서버 CA가 필요하므로 마지막 단계에서는 도구 상자 창으로 이동하여 StartCom CA 인증서를 선택합니다.

이 화면에서 마우스 오른쪽 버튼을 클릭하고 두 개의 파일로 저장합니다.

<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 파일)를 암호화하지만 사이트 암호화를 처리하려면 웹 서버에 암호화되지 않은 버전이 필요합니다. 암호화를 해제하려면 서버에 복사하고 다음 명령을 사용하여 private.key 파일로 해독하십시오.

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

OpenSSL은 비밀번호를 묻습니다. StartSSLs 웹사이트에서 입력한 비밀번호에 비밀번호를 입력하세요.

이 시점에서 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를 구성하는 방법에 대해 설명합니다. 이 지침은 최신 버전의 Ubuntu VPS에서 실행되는 Apache에 대한 것입니다. 다른 Linux 기반 배포판 또는 웹 서버의 경우 그에 따라 조정해야 합니다.

먼저 키를 잘 저장할 폴더를 만듭니다. 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

이 명령으로 Apaches 로그 파일을 확인하여 표시 중지 오류가 있는지 확인할 수 있습니다.

cat /var/log/apache2/error.log

모든 것이 좋아 보인다면 HTTPS URL(예: 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>