Setting up Apache HTTPS/SSL on Windows

from http://rubayathasan.com/tutorial/apache-ssl-on-windows/

I am assuming that you already have Apache2 installed and working on a Windows server.

For SSL/HTTPS to work you need to download and setup the Win32 Binary including OpenSSL "httpd/apache_x.x.x-win32-x86-openssl-x.x.x.msi" on your Windows server.

If you now have regular HTTP server working follow the guide below to setup HTTPS.

 

Setting up HTTPS on a Windows Server:

 

  • Creating a self-signed SSL Certificate using OpenSSL:

    Open the command prompt and cd to your Apache installations "bin" directory. Usually it would be:

    cd "C:\Program Files\Apache Software Foundation\Apache2.2\bin"

    To create the SSL certificate we will need the openssl.cnf files location but the default location set by OpenSSL for this file is setup according to a Linux distribution, so we need to fix it for Windows.

    We need to setup the Windows environment variable OPENSSL_CONF to point to the openssl.cnf files location. It is usually located in "C:\Program Files\Apache Software Foundation\Apache2.2\conf\openssl.cnf" directory.

    So we can set it up by the following command or through the GUI interface:

    set OPENSSL_CONF=C:\Program Files\Apache Software Foundation\Apache2.2\conf\openssl.cnf

    All files generated from the following commands will reside in "C:\Program Files\Apache Software Foundation\Apache2.2\bin" folder.

    Now that we have the environment variable set we need to create a new OpenSSL certificate request using the following command:

     

    openssl req -new -out server.csr

    It will ask you some questions and you can safely ignore them and just answer the following questions:
    PEM pass phrase: Password associated with the private key you’re generating (anything of your choice). 
    Common Name: The fully-qualified domain name associated with this certificate (i.e. www.your-domain.com).

    Now we need to remove the passphrase from the private key. The file "server.key" created from the following command should be only readable by the apache server and the administrator. You should also delete the .rnd file because it contains the entropy information for creating the key and could be used for cryptographic attacks against your private key.

    openssl rsa -in privkey.pem -out server.key

    Now we need to set up an expiry date, it could be any time of your choice, we use 365 days below:

    openssl x509 -in server.csr -out server.cert -req -signkey server.key -days 365

    We have the Self-signed SSL certificates ready now. Now We need to MOVE the "server.cert" and "server.key" file to the

    "C:\Program Files\Apache Software Foundation\Apache2.2\conf" location.

  • Configuring Apache to run SSL/HTTPS server:

    Now that we have the Self-signed SSL certificate ready, all we need is to configure Apache to start the SSL server.

    First we modify the "C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf" file.

    Open up conf\httpd.conf in a text editor and look for the line:

    LoadModule ssl_module modules/mod_ssl.so and remove any pound sign (#) characters preceding it.

    Include conf/extra/httpd-ssl.conf and remove any pound sign (#) characters preceding it.

    Now we need to modify the "C:\Program Files\Apache Software Foundation\Apache2.2\conf\extra\httpd-ssl.conf". Let all the default options as it is but make sure to modify the following section according to your need:

    <VirtualHost _default_:443>
        ServerAdmin some@email.com
        DocumentRoot "Your Root folder location"
        ServerName www.domain.com:443
        ServerAlias domain.com:443
        ErrorLog "logs/anyFile-error.log"
        CustomLog "logs/anyFile-access.log" common
        SSLEngine on

        SSLCertificateFile "C:/Program Files/Apache Software Foundation/Apache2.2/conf/server.cert"

        SSLCertificateKeyFile "C:/Program Files/Apache Software Foundation/Apache2.2/conf/server.key"
    </VirtualHost>

    Make sure that "SSLCertificateFile" and "SSLCertificateKeyFile" are properly located.

    For better organizing you can also put the whole <VirtualHost></VirtualHost> section in the "C:\Program Files\Apache Software Foundation\Apache2.2\conf\extra\httpd-vhosts.conf" along with your other Virtual Host settings there but you need to uncomment “Include conf/extra/httpd-vhosts.conf” in your conf\httpd.conf file to use that.

  • Opening SSL/HTTPS port on Windows:

    Now we need to open an exception in Windows Firewall for TCP port 443. You can do that by going to “Windows Firewall” settings in Control Panel and adding a port in the exception section.

Well that was long and painful but but now Restart the server and everything should work fine.

Please feel free to leave comments if this guide helped.

Create Self-Signed CertificateC

arrow
arrow
    全站熱搜

    zer931 發表在 痞客邦 留言(0) 人氣()