How To Set Up Apache with a Free Signed SSL Certificate on a VPS

Prerequisites

Before we get started, here are the web tools you need for this tutorial:

  1. Google Chrome browser
  2. Apache installed on your VPS (cloud server)
  3. A domain name you own
  4. Access to an email address at that domain, either:
    1. [email protected]
    2. [email protected]
    3. [email protected]

StartSSL.com offers completely free verified (your users won‘t have to see those scary red screens saying "this site isn‘t trusted" anymore) SSL certificates that you can use on your website. This is a great deal as most companies charge $50-$60 for similar services. The free version is a bit tricky to set up, but it‘s well worth it.

To get started, browse to StartSSL.com and using the toolbar on the left, navigate to StartSSL Products and then to StartSSL™ Free. Choose the link for Control Panel from the top of the page.

Make sure you are using Google Chrome

  1. Choose the Express Signup. option
  2. Enter your personal information, and click continue.
  3. You‘ll get an email with a verification code inside it shortly. Copy and paste that email into the form on StartSSL‘s page.
  4. 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.
  5. 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.
  6. 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".
  7. Once your key is ready, click Install.
  8. Chrome will show a popdown that says that the certificate has been succesfully installed to Chrome.

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 Control panel 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.

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 Control panel and set Type to Domain Name Validation. You‘ll be prompted to choose from an email at your domain, something like [email protected]

Check the email inbox for the email address you selected. You will get yet another verification email at that address, so like before, copy and paste the verification code into the StartSSL website.

Next, go to the Certificates Wizard tab and choose to create a Web Server SSL/TLS Certificate.

Hit continue and then enter in a secure password, leaving the other settings as is.

You will be shown a textbox that contains your private key. Copy and paste the contents into a text editor and save the data into a file called ssl.key.

When you click continue, you will be asked which domain you want to create the certificate for:

Choose your domain and proceed to the next step.

You will be asked what subdomain you want to create a certificate for. In most cases, you want to choose www here, but if you‘d like to use a different subdomain with SSL, then enter that here instead:

StartSSL will provide you with your new certificate in a text box, much as it did for the private key:

Again, copy and paste into a text editor, this time saving it as ssl.crt.

You will also need the StartCom Root CA and StartSSL‘s Class 1 Intermediate Server CA in order to authenticate your website though, so for the final step, go over to the Toolbox pane and choose StartCom CA Certificates:

At this screen, right click and Save As two files:

  • StartCom Root CA (PEM Encoded) (save to ca.pem)
  • Class 1 Intermediate Server CA (save to sub.class1.server.ca.pem)

For security reasons, StartSSL encrypts your private key (the ssl.key file), but your web server needs the unencrypted version of it to handle your site‘s encryption. To unencrypt it, copy it onto your server, and use the following command to decrypt it into the file private.key:

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

OpenSSL will ask you for your password, so enter it in the password you typed in on StartSSL‘s website.

At this point you should have five files. If you‘re missing any, double-check the previous steps and re-download them:

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

You can discard the ssl.key file. If you haven‘t already copied the others onto your server you upload them there now:

scp {ca.pem,private.key,sub.class1.server.ca.pem,ssl.crt} YOURSERVER:~

Activating the certificate in Apache

Having a certificate isn‘t any good if you can‘t actually use it. This section explains how to configure Apache to use your new SSL certificate. These instructions are for Apache running on recent versions of Ubuntu VPS. For other Linux-based distros or web servers, you‘ll have to adjust accordingly.

First, create the folders where we‘ll store the keys. Enable Apache‘s SSL module, and restart Apache.

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

Copy the files you set up in the previous section into the /etc/apache2/ssl folder on your VPS.

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

Execute:

ls /etc/apache2/ssl

And it should return:

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

Now, open your apache2 configuration file. Unless you‘ve already modified the default configuration, input:

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

It should look something like this:

<VirtualHost *:80>
    ServerAdmin [email protected]

    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>

Copy the entire script above (from <VirtualHost *:80> to </VirtualHost>), paste it below the existing one, and change the top line from:

<VirtualHost *:80>

to

<VirtualHost *:443>

And add the following lines after the <VirtualHost *:443> line:

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 

The end result should look like this:

<VirtualHost *:80>
    ServerAdmin [email protected]

    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 [email protected]

    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>

Save your files and restart Apache with:

sudo service apache2 restart

You can check Apache‘s log files to see if there are any show stopping errors with this command:

cat /var/log/apache2/error.log

If everything looks good, try accessing your site in your web browser using an HTTPS URL (e.g. https://www.YOURSITE.com). When your site loads, you should see a little green padlock icon next to the URL. Click on it and you should see the following. The connections tab should show that the site‘s identity has been verified by StartCom.

Congratulations! You are all set!

Reference Links:

Here are some of the other posts I consulted when putting this together. If you run into any problems they might be a source of inspiration on how to fix them:

Submitted by: Nik van der Ploeg

原文:

https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-with-a-free-signed-ssl-certificate-on-a-vps

时间: 2025-01-15 04:20:30

How To Set Up Apache with a Free Signed SSL Certificate on a VPS的相关文章

How To Create a SSL Certificate on Apache for CentOS 6

About Self-Signed Certificates 自签证书.一个SSL证书,是加密网站的信息,并创建更安全的链接的一种方式.附加地,证书可以给网站浏览者显示VPS的的身份证明信息.如果一个SSC没有第三方证实,那么证书作者可以发行SSL证书,用以验证虚拟服务器的细节. Step One-Install Mod SSL 为了设置自签名证书,我们先要确保Apache和Mod SSL已经在VPS上安装.你可以通过下面的命令安装他们: yum install mod_ssl Step Two

Apache 配置HTTPS协议搭载SSL配置

在设置Apache + SSL之前, 需要做: 安装Apache, 请参见: Windows环境下Apache的安装与虚拟目录的配置, 下载安装Apache时请下载带有ssl版本的Apache安装程序. 在进行下一步之前, 请确认Apache已经安装并可以正常工作. 并且ssl需要的文件在如下的位置: [Apache安装目录]/modules/ mod_ssl.so [Apache安装目录]/bin/ openssl.exe, libeay32.dll, ssleay32.dll [Apache

windows Apache 配置支持HTTPS协议SSL证书

在设置Apache + SSL之前, 需要做: 安装Apache, 下载安装Apache时请下载带有ssl版本的Apache安装程序. 并且ssl需要的文件在如下的位置: [Apache安装目录]/modules/ mod_ssl.so [Apache安装目录]/bin/ openssl.exe, libeay32.dll, ssleay32.dll, openssl.cnf [Apache安装目录]/conf/ openssl.cnf 创建SSL证书(注意,我下载的是PHPStudy里面自带了

Apache配置HTTPS协议搭载SSl配置全过程

1.安装必要的软件 从Apache官方(www.apache.org)下载必要的ApacheHttpServer安装包,可以直接官方提供的绑定openssl的apache.文件名是:httpd-2.2.15-win32-x86-openssl-0.9.8m-r2.msi(我用的是Apache2.2.15for windows的版本,你可以点击此处下载最新的版本进行安装,最好选择含有openssl版本的哦)否则单独安装windows下的openssl比较麻烦,要么找到一个第三方的编译结果,要么自己

apache站点身份验证以及SSL证书的实现

案例:SSL证书的实现 原理:为了实现httpd站点的安全性,在web服务器上安装服务器证书,客户端浏览器与服务器证书建立SSL连接,在SSL连接上传输的数据进行加密,SSL证书主要用于服务器的数据传输链路加密和身份认证,绑定网站域名. 配置web服务器(linux) 1.安装httpd.软件 yum --disablerepo=\* --enablerepo=c6-media install httpd -y 2.service httpd start开启httpd服务 3.cd /var/w

windows下面配置apache+https(利用SSL)服务器

1.下载带有openSSL的apache安装包,我下载的为apache_2.2.11-win32-x86-openssl-0.9.8i.msi,安装后确认一下bin路径下的openssl.exe,ssleay32.dll和libeay32.dll,无误进行下一步. 2.修改两个配置文件,一个为conf/httpd.conf,另一个为conf/extra/httpd-ssl.conf (a)修改httpd.conf 为了使apache启动的时候调用ssl的服务,我们需要在配置文件中做一些修改.找到

Apache Virtual Hosting IP Based and Name Based Virtual Hosts

As we all are aware that Apache is a very powerful, highly flexible and configurable Web server for Nix OS. Here in this tutorial, we are going to discuss one more feature of Apachewhich allows us to host more than one website on a single Linux machi

使用腾讯证书服务为Centos7+Apache申请颁发证书

说到证书我们大家都知道,证书可以提高数据加密传输,但是提到证书服务的供应商,相对比较多可以根据自己的需求来定,今天我们使用腾讯的云服务平台中的证书服务来为Centos7下的Apache服务申请及分配证书,现在的第三方证书服务都现在都简化了,无需提供csr文件即可生成证书及私钥文件,所以我们无需申请相关的csr证书申请文件了,还需要注意此次过程中,我们需要有自己有公网域名,因为在申请证书的时候需要验证.具体见下: 腾讯云服务地址:https://console.qcloud.com/ 我们首先需要

APACHE安装配置说明

一.软件下载 1.apache:http://archive.apache.org/dist/httpd/httpd-2.2.12.tar.gz或者http://apache.etoak.com/httpd/httpd-2.2.13.tar.gz 二.环境检查 # rpm -qa|grep zlibzlib-devel-1.2.3-3zlib-1.2.3-3# rpm -qa|grep sslopenssl-devel-0.9.8b-10.el5openssl-0.9.8b-10.el5 如果需