2

I'm trying to get SSL to run on my apache web server.

I do not have the DNS for the domain setup yet is that an issue?

How do I setup SSL on my web server?

When I start apache it fails.

root@vannevar:/etc/apache2/ssl# service apache2 start
 * Starting web server apache2                                                                                                                         Action 'start' failed.
The Apache error log may have more information.

The log stats that it's unable to read the certificate.

[Thu Jun 28 15:01:02 2012] [error] Init: Unable to read server certificate from file /etc/apache2/ssl/www.example.com.csr
[Thu Jun 28 15:01:02 2012] [error] SSL Library Error: 218529960 error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag
[Thu Jun 28 15:01:02 2012] [error] SSL Library Error: 218595386 error:0D07803A:asn1 encoding routines:ASN1_ITEM_EX_D2I:nested asn1 error

The contents of /etc/apache2/httpd.conf

ServerName [SERVERIP]

The contents of /etc/apache2/ports.conf

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default
# This is also true if you have upgraded from before 2.2.9-3 (i.e. from
# Debian etch). See /usr/share/doc/apache2.2-common/NEWS.Debian.gz and
# README.Debian.gz

NameVirtualHost [SERVERIP]:443
NameVirtualHost *:80
Listen 80

<IfModule mod_ssl.c>
    # If you add NameVirtualHost *:443 here, you will also have to change
    # the VirtualHost statement in /etc/apache2/sites-available/default-ssl
    # to <VirtualHost *:443>
    # Server Name Indication for SSL named virtual hosts is currently not
    # supported by MSIE on Windows XP.
    Listen 443
</IfModule>

<IfModule mod_gnutls.c>
    Listen 443
</IfModule>

The contents of /etc/apache2/sites-available/www.example.com

<VirtualHost *:80>
     ServerAdmin [email protected]
     ServerName example.com
     ServerAlias www.example.com
     DocumentRoot /srv/sites/example.com/public/
     ErrorLog /srv/sites/example.com/logs/error.log
     CustomLog /srv/sites/example.com/logs/access.log combined
</VirtualHost>

<VirtualHost [SERVERIP]:443>
     SSLEngine On
     SSLCertificateFile /etc/apache2/ssl/www.example.com.csr
     SSLCertificateKeyFile /etc/apache2/ssl/www.example.com.key
     SSLCACertificateFile /etc/apache2/ssl/comodo.crt

     ServerAdmin [email protected]
     ServerName example.com
     ServerAlias www.example.com
     DocumentRoot /srv/sites/example.com/public/
     ErrorLog /srv/sites/example.com/logs/error.log
     CustomLog /srv/sites/example.com/logs/access.log combined
</VirtualHost>

UPDATE:

In dreamhost (which i'm trying to get off of) I already have a domain with ssl / https I can see the three keys in the dreamhost admin certificate, private key, and intermediate certificate. Can I do anything with these? I can see that dreamhost is using comodo and my website says its PositiveSSL so... on comodo's website there is the root certificate and intermediate certificate. What do these five certificates have to do with the two created by the openssl req -new -days 365 -nodes -keyout www.mydomain.com.key -out www.mydomain.com.csr command? These two are requesting the actual certificate?

I realized that apache's error is referring to the file /etc/apache2/sites-available/www.example/com where I messed up the file type for SSLCertificateFile /etc/apache2/ssl/www.example.com.csr it's supposed to be .crt according to the linode docs

Update 2

So I went into dreamhost and coppied the keys to the following files and mapped the following

certificate => dh.crt
private key => dh.key
intermediate certificate => dh.cer

changed the connection in /sites-available/example.com and it worked (apache worked). Does this mean that ssl will work when I connect my domain?

5 Answers 5

3

I can't vote up on here, or comment, but Adrian Perez is right, you aren't using a certificate but a certificate signing request, on this line:

SSLCertificateFile /etc/apache2/ssl/www.example.com.csr

The CSR needs to be sent to a certificate authority to verify your identity and generate the certificate. You can self generate this using the command:

openssl x509 -req -days 365 -in www.example.com.csr -signkey www.example.com.key -out www.example.com.crt

And changing:

SSLCertificateFile /etc/apache2/ssl/www.example.com.csr

To:

SSLCertificateFile /etc/apache2/ssl/www.example.com.crt

But then you'll get warnings when you visit the site in your browser, as this would be a self signed certificate and therefore not trusted. Still, it's a good way to get your head around the process and test that the site is working. The basic steps are:

  1. Generate a private Key file (only do this once, the first time you set up a site)
  2. Generate a Certificate signing request
  3. Pay a ton of money to a Certificate Authority to verify and issue the certificate (Thwate or similar)
  4. Put key on server.

Regarding permissions, make sure the key/crt are only readable/writable by root (chmod 600) otherwise Apache will moan.

Hope this helps

2
  • I updated the question with a little bit of what has been going on in my head, care to take a look? Jun 28, 2012 at 22:43
  • In order to test if the SSL is working on your Vhost, just make an amendment to your hosts file so that www.example.com (or whatever domain you've set up) points to the IP address of your server. Jul 3, 2012 at 13:36
0

Seems like your cert file is unreadable (or missing)

[Thu Jun 28 15:01:02 2012] [error] Init: Unable to read server certificate from file /etc/apache2/ssl/www.example.com.csr

Did you check for permissions/paths?

Also, the dns has to be set-up or the certificate will show some error (depends on the browser)

3
  • I'm ok with the browser showing an error as long as it is set up and ready for me to setup dns. I'm checking the permissions now. Jun 28, 2012 at 20:52
  • Its not permissions just made the csr 777 and the error is still there. Jun 28, 2012 at 21:08
  • here's your answer iamsect.ncl.ac.uk/deliverables/docs/target/ar01s05.html Take care not to mix up the ‘csr’ (certificate signing request) and ‘crt’ (the signed certificate) in the ssl.conf file didnt notice its a CSR file, guess its not meant to be in the configat all
    – MitziMeow
    Jun 28, 2012 at 22:12
0

You can download a Java program called Keystore Explorer to open and view the certificate to verify that it is valid. On thing with Apache is that the cert needs to be in a certain format. This website might help explain the format you need, which appears to be PEM .

2
  • I used openssl req -new -days 365 -nodes -keyout www.mydomain.com.key -out www.mydomain.com.csr which is straight from the linode docs. Could this really be the case? Jun 28, 2012 at 21:20
  • That looks like it would generate a PEM to me. Therefore, if you used that CSR to request a cert reply, it should be ok.
    – djangofan
    Jul 1, 2012 at 3:19
0

Maybe i'm wrong but check if the file www.example.com.csr contains the certificate. Generally files with csr extension contains the request to be signed in a CA.

Also, you can check the permission and paths like another user has said, but i think the problem is about the content in the file.

You can check to delete the file and create a new blank file, and paste the certificate data into the file.

Regards!

2
  • I created those files using openssl req -new -days 365 -nodes -keyout www.mydomain.com.key -out www.mydomain.com.csr which is straight from the linode docs. They have stuff in them. Jun 28, 2012 at 21:53
  • Except that's a certificate signing request (hence the req part). You need the actual certificate. Jun 28, 2012 at 22:15
0

You can't setup SSL until you have the actual certificate. What you have is a request for a certificate that should be sent to a certificate authority to have them issue a certificate. Also, while you can get the server working without DNS working, clients won't be able to access the server except by IP, which will generate a warning since the certificate can't validate the IP.

Update: It sounds like you've done everything right now. If there are any other issues, you can resolve them once the DNS is setup.

1
  • I have certificates updates question. ^^ Jun 28, 2012 at 23:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .