Posted by Steve on Thu 9 Feb 2006 at 11:27
With the introduction of the Apache2 packages in Debian it is much simpler to create and use a secure SSL protected webserver than in the old days with Apache 1.3, here we'll show how it is done.
If you have Apache 2.x installed already then you're good to go as you don't need anything extra installed.
If you haven't got it installed then you can do so easily:
earth:~# apt-get install apache2 Reading Package Lists... Done Building Dependency Tree... Done The following extra packages will be installed: apache2-common apache2-mpm-worker apache2-utils openssl ssl-cert Suggested packages: apache2-doc ca-certificates The following NEW packages will be installed: apache2 apache2-common apache2-mpm-worker apache2-utils openssl ssl-cert 0 upgraded, 6 newly installed, 0 to remove and 0 not upgraded. Need to get 2040kB of archives. After unpacking 6218kB of additional disk space will be used. Do you want to continue? [Y/n]
Once the server is installed you need to do three things to get a working SSL setup:
Generating A Certificate
Generating a certificate from scratch will give you something which will be used to protect the traffic exchanged between clients and your server, however it will be signed by a untrusted certificate authority so it will generate warnings.
Importing a paid and "trusted" certificate will avoid this problem, but that is beyond the scope of this simple introduction.
Generating an SSL certificate for Apache2 may be accomplished using the apache2-ssl-certificate script. This will ask you questions interactively then generate the certificate file appropriately.
Here's a sample session:
earth:~# apache2-ssl-certificate creating selfsigned certificate replace it with one signed by a certification authority (CA) enter your ServerName at the Common Name prompt If you want your certificate to expire after x days call this programm with -days x Generating a 1024 bit RSA private key ............++++++ ..........................++++++ writing new private key to '/etc/apache2/ssl/apache.pem' ----- You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [GB]: State or Province Name (full name) [Some-State]:Scotland Locality Name (eg, city) []:Edinburgh Organization Name (eg, company; recommended) []:Steve Kemp Organizational Unit Name (eg, section) []: server name (eg. ssl.domain.tld; required!!!) []:earth Email Address []: earth-admin@steve.org.uk
Enabling SSL Support
To use the SSL facilities of Apache2 you must enable the module mod_ssl, this can be achieved using the helper tool a2enmod (We've previously discussed the Apache2 helper scripts.)
As root run:
earth:~# a2enmod ssl Module ssl installed; run /etc/init.d/apache2 force-reload to enable.
Once this is done you'll have Apache setup to accept SSL connections, but the server will still only be listening for incoming HTTP requests on port 80 - and not SSL connections on port 443. To fix this you must add a line to the file /etc/apache2/ports.conf:
Listen 443
With these two steps out of the way you now have an Apache setup which will listen for and accept SSL connections. The next step is to modify your virtualhosts to use it.
Configuring your SSL Hosts
With a certificate setup, and the server updated to load and listen for incoming SSL connections you're almost finished. The final step is to ensure that your virtual hosts, or main host, will accept SSL options.
I use virtual hosts upon my machine and this just means adding a couple of options to each one I wish to use SSL:
SSLEngine on SSLCertificateFile /etc/apache2/ssl/apache.pem
For reference here is a complete example which should be easy to modify/understand:
NameVirtualHost *:443
NameVirtualHost *:80
<VirtualHost *:80>
ServerName earth.my.flat
DocumentRoot /var/www/
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined
</VirtualHost>
<VirtualHost *:443>
ServerName earth.my.flat
DocumentRoot /var/www/
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/apache.pem
</VirtualHost>
I thought the introduction would be sufficient to make it clear. Still its a good suggestion and I have no strong preference either way so I've changed it now.
Thanks.
[ Parent ]
[ Parent ]
[ Parent ]
apache2ctl restart
[ Parent ]
[ Parent ]
Did you restart the server afterwards?
/etc/init.d/apache2 restart
Failing that I'd look to see that you don't have port 80 listed elsewhere:
rgrep 80 /etc/apache2/
[ Parent ]
NameVirtualHost *:443
<VirtualHost *:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
LogLevel warn
CustomLog /var/log/apache2/access.log combined
ServerSignature On
# [2006-02-09] added to enable SSL as per
# http://www.debian-administration.org/articles/349
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/apache.pem
</VirtualHost>
Listen 443
[ Parent ]
[ Parent ]
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
apache2 11488 root 3u IPv6 1442337 TCP *:https (LISTEN)
apache2 11489 www-data 3u IPv6 1442337 TCP *:https (LISTEN)
apache2 11490 www-data 3u IPv6 1442337 TCP *:https (LISTEN)
apache2 11495 www-data 3u IPv6 1442337 TCP *:https (LISTEN)
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
Is the root certificate for this CA included in any major browser?
If so they are usable, if not then they are not.
I see no information on the site except that this is one of their goals. No indication of whether they've succeeded ...
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
I guess you mean ApacheFriends.org ?
That is one solution for installing Apache + PHP + etc, but it is not ideal for Debian systems since it doesn't work with our packing system - and means that upgrades and security patches will need to be handled differently. Also looking at their webpages it doesn't mention SSL. Is that setup too?
Maybe when you have a single machine you can deal with that, but if you're looking after a lot it is best to stick to standard sources so you can patch them all in the same way ..
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
SSL has nothing to do with username / password authentication.
I'd suggest that you have some other changes present in your Apache2 setup which is causing this.
Look for either .htaccess files beneath your documentroot, or "Require" settings somewhere inside /etc/apache2.
For more help you may find the debian-user mailing list helpful ...
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
The error means the server name used by your webserver (ie "www.example.com") is different from the name of the certificate.
Generate another one as described above but make sure you enter an identical name to the server's external hostname.
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
Without using multiple IP addresses you cannot have more than one SSL server upon a single host.
If you had a "wildcard certificate" then it would work - but two different ones? Not at all.
See the Apache documentation for details.
[ Parent ]
[ Parent ]
[ Parent ]
You've probably enabled the CGI handling for the non-SSL site, but not for the SSL one.
If you give an example of the URL which is failing (eg. is it /some/path/foo.cgi ?) then we might be able to help.
[ Parent ]
[ Parent ]
OK I see the problem there:
Inside the SSL virtualhost you're using you should add the following:
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>
That will probably be enough. (Run "/etc/init.d/apache2 restart" afterwards!)
If that doesn't help then please post the configuration files for both the http and the https sites - basically you want to make them match so that the same CGI settings apply to both..
PS.
[ Parent ]
You got lucky :)
Your question was fairly easy understand, and you came back to supply followup details. Too often people ask questions and don't give enough useful information to identify their problems, or simply never return to answer any questions.
Still I'm glad you're impressed. I think the visitors here all do a great job of helping each other.
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
Not present. Run this:
export RANDFILE=/dev/random openssl req $@ -new -x509 -days 365 -nodes -out \ /etc/apache2/ssl/apache.pem -keyout /etc/apache2/ssl/apache.pem chmod 600 /etc/apache2/ssl/apache.pem
[ Parent ]
[ Parent ]
[ Parent ]
Allow you to pass additional arguments to the command if you wish.
Out of context it looks strange, but in a shell-script it works as expected.
[ Parent ]
[ Parent ]
Question:
The script makes a symbolic link, that is named using the hash of the "key+certificate" file.
ln -sf /etc/apache2/ssl/apache.pem \
/etc/apache2/ssl/`/usr/bin/openssl \
x509 -noout -hash < /etc/apache2/ssl/apache.pem`.0
Why is this needed?
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
True. See the earlier comment in this article for alternative instructions.
[ Parent ]
[ Parent ]
[ Parent ]
True. Read the comments on this article and you'll see this has been mentioned already, along with a solution.
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
I use this for creating a new CERT - I'm sorry to say I have no idea how to extend and existing cert.
export RANDFILE=/dev/random openssl req -new -x509 -days 1000-nodes -out \ /etc/apache2/ssl/apache.pem -keyout /etc/apache2/ssl/apache.pem chmod 600 /etc/apache2/ssl/apache.pem
[ Parent ]
You'll need to restart your Apache server to make it re-read the key:
/etc/init.d/apache2 restart
Also it might be worth double-checking you're referring the file that we created (/etc/apache2/ssl/apache.pem) in your Apache configuration, not another key file.
[ Parent ]
[ Parent ]
The best way is to generate your key without a passphrase.
[ Parent ]
[ Parent ]
The best way is to generate your key without a passphrase in the first place.
Like I said before.
You can remove one easily enough...
[ Parent ]
[ Parent ]
OK lets take it from the top.
Your options are either:
Since you don't show exactly what went wrong I think generating a new key should be the easiest route. As root run:
export RANDFILE=/dev/random openssl req -new -x509 -days 1000 -nodes -out /etc/apache2/ssl/apache.pem -keyout /etc/apache2/ssl/apache.pem chmod 600 /etc/apache2/ssl/apache.pem /etc/init.d/apache2 restart
That should work pretty well.
[ Parent ]
Great, glad we got there in the end.
I have a wishlist at amazon, linked to on my profile page, but honestly a "thank you" comment is just as good.
Submitting new articles is even more useful!
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]