Primera presa de contacte: funcionament mínim.
Instal·lem apache2:
# aptitude install apache2
Si quan s'enguega l'apache obtenim el missatge següent:
-- apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
cal revisar els continguts del fitxer /etc/hosts. Hauria de ser semblant a:
127.0.0.1 localhost
10.138.57.2 perafita.guifi.net perafita
Apache2 a Debian:
- fitxers de configuració -> /etc/apache2
- fitxers a servir -> /var/www
- es crea el grup de sistema (/etc/group) www-data
Instal·lem l'openssl i ens generem un certificat:
# aptitude install openssl ssl-cert
# openssl req $@ -new -x509 -days 365 -nodes -out /etc/apache2/apache.pem -keyout /etc/apache2/apache.pem
Configurem l'apache2 perquè també escolit el port per on es faran les comunicacions ssl afegint a l'arxiu /etc/apache2/ports.conf la línia del port 443:
Listen 80
Listen 443
Carreguem el mòdul ssl de l'apache:
# a2enmod ssl
Reengeguem l'apache perquè s'executi amb el mòdul d'ssl:
# /etc/init.d/apache2 restart
Definim els virtual hosts a /etc/apache2/sites-available/default:
NameVirtualHost *:80
NameVirtualHost *:443
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
# This directive allows us to have apache2's default start page
# in /apache2-default/, but still have / go to the right place
RedirectMatch ^/$ /apache2-default/
</Directory>
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>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
ServerSignature On
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
# This directive allows us to have apache2's default start page
# in /apache2-default/, but still have / go to the right place
RedirectMatch ^/$ /apache2-default/
</Directory>
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>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
ServerSignature On
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
SSLEngine on
SSLCertificateFile /etc/apache2/apache.pem
</VirtualHost>
Bàsicament el que s'ha fet és:
canviar
NameVirtualHost *
per
NameVirtualHost *:80
NameVirtualHost *:443
<VirtualHost *>
per
<VirtualHost *:80>
copiar tota la secció <VirtualHost *> ... </VirtualHost>
fer-hi les modificacions següents:
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /etc/apache2/apache.pem
</VirtualHost>
Recarreguem les configuracions de l'apache per fer efectius els canvis:
# /etc/init.d/apache2 reload
Ara amb un navegador ja podem obrir la URL https://localhost (ep, https, i no http, que per això estem activant l'ssl) i comprovar-ne els resultats: se'ns servirà el certificat, i, si l'acceptem, entrarem a la plana web que se'ns serveixi.
Bibliografia:

