How to Configure Apache2 SSL

SSL (Secure Sockets Layer) is a way of providing security over an Internet connection by using a public and private key pair. For a truly secure connection, a third party trusted Certificate Authority's public key is used. For testing purposes and private networks, it is possible to create a self-signed certificate. The Apache2 Web server's mod_ssl module allows you to create a secure website using SSL. The OpenSSL software is used to create the private and public keys.

Things You'll Need

  • Apache2 HTTP Server
  • mod_ssl module
  • OpenSSL
  • Linux or Unix operating system
Show More

Instructions

    • 1

      Download and install Apache2 with the mod_ssl module and OpenSSL.

    • 2

      Open a terminal window.

    • 3

      Type the command "openssl genrsa -out cert.key 1024" to create the private SSL key.

    • 4

      Type "openssl req -new -key cert.key -out cert.csr" and send the ".csr" file to a Certificate Authority to generate a Certificate Authority signed certificate. Type "openssl req -new -key cert.key -x509 -out cert.crt" to create a self-signed certificate.

    • 5

      Place the private key in the "/etc/apache2/ssl.key/" directory.

    • 6

      Place the certificate in the "/etc/apache2/ssl.crt/" directory.

    • 7

      Type the command "a2enmod ssl" to enable the Apache mod_ssl module.

    • 8

      Open the "/etc/apache2/httpd.conf" file in any text editor.

    • 9

      Add the following three lines to top of the file:
      NameVirtualHost *:80
      NameVirtualHost *:443
      Listen 443
      This instructs the Web server to expect traffic on both port 80 and port 443.

    • 10

      Add a "VirtualHost" directive for port 80:
      <VirtualHost *:80>
      ServerAdmin webmaster@example.com
      DocumentRoot /var/www/htdocs/example
      ServerName www.example.com
      ServerAlias example.com
      </VirtualHost>

    • 11

      Add a "VirtualHost" directive for port 443:
      <VirtualHost *:443>
      ServerAdmin webmaster@example.com
      DocumentRoot /var/www/htdocs/example-secure
      ServerName secure.example.com
      SSLEngine on
      SSLCertificateFile /etc/apache2/ssl.crt/cert.crt
      SSLCertificateKeyFile /etc/apache2/ssl.key/cert.key
      </VirtualHost>

    • 12

      Add a "Directory" directive that states the SSL must be used when serving the contents of the secure directory:
      <Directory /var/www/htdocs/example-secure>
      SSLRequireSSL
      </Directory>

Related Searches:

References

Resources

Comments

You May Also Like

Related Ads

Featured