How to setup Apache SSL (Self-signed Certificate) on Ubuntu 9.04

  1. Install openssl
    # sudo apt-get install openssl
  2. Create a serect key (e.g. server.key)
    # sudo openssl genrsa -out server.key 4096 (e.g. no password - do not use 2048 byte key)
    # sudo openssl genrsa -des3 -out server.key 4096 (do not use 2048 byte key)
  3. Alternative: Skip (invalidate) a password (e.g. server.key)
    # sudo  openssl genrsa -out server.key 4096
  4. Create a public key (e.g. server.csr)
    # sudo openssl req -new -key server.key -out server.csr
  5. Create a signed certificate(e.g. server.crt / Expiration is ten (10) years)
    # sudo openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt
  6. Copy the keys to an appropriate directory (Note a permission to copy destination)
    # sudo cp server.crt /etc/ssl/certs/; sudo cp server.key /etc/ssl/private/
  7. Edit /etc/apache2/sites-available/default-ssl
    # sudo vi /etc/apache2/sites-available/default-ssl

    # Comment out the following two lines:
    # SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
    # SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key

    # Add the following two lines:
    SSLCertificateFile /etc/ssl/certs/server.crt
    SSLCertificateKeyFile /etc/ssl/private/server.key
  8. Enable mod_ssl (Apache2 SSL module)
    # sudo a2enmod ssl
    # sudo a2ensite default-ssl
  9. Restart Apache2 (Answer the secret key's password)
    # sudo /etc/init.d/apache2 force-reload && sudo /etc/init.d/apache2 restart
  10. (Optional) Aways enable SSL
    # sudo a2enmod rewrite
    # sudo vi /etc/apache2/sites-available/default

    # Insert these lines at the bottom part in between<VirtualHost *:80>...</VirtualHost>
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
  11. (Optional) Add +ExecCGI
    # sudo vi /etc/apache2/sites-available/default-ssl
トラックバック URL: https://perltips.twinkle.cc/trackback/345