Apache HTTP Server: differenze tra le versioni

 
(28 versioni intermedie di uno stesso utente non sono mostrate)
Riga 10: Riga 10:


{{Box|Info|Questa guida fa riferimento alle versioni di apache 2.4 e successive.}}
{{Box|Info|Questa guida fa riferimento alle versioni di apache 2.4 e successive.}}
Per una guida dedicata a Stretch che tratta un server LAMP nel suo complesso vedere [http://guide.debianizzati.org/index.php/Installare_un_ambiente_LAMP:_Linux,_Apache2,_SSL,_MySQL,_PHP5_-_Stretch#Apache2:_layout_di_configurazione questa pagina].


== Installazione ==
== Installazione ==
Riga 39: Riga 41:
</pre>
</pre>
Se ciò non fosse vero, per esempio perché si sta usando una VPS remota, evidentemente sarà necessario avere un dominio registrato ed inserire i dati corretti (ma si tratterebbe di un caso di utilizzo avanzato e pertanto chi legge dovrebbe già avere le competenze per risolvere il problema).
Se ciò non fosse vero, per esempio perché si sta usando una VPS remota, evidentemente sarà necessario avere un dominio registrato ed inserire i dati corretti (ma si tratterebbe di un caso di utilizzo avanzato e pertanto chi legge dovrebbe già avere le competenze per risolvere il problema).
=== Moduli aggiuntivi ===
==== PHP ====
Uno dei moduli più gettonati è senz'altro quello che permette l'integrazione di Apache con PHP:
<pre># apt install libapache2-mod-php</pre>


== Configurazione ==
== Configurazione ==
Riga 168: Riga 177:
e similmente disattivarlo con
e similmente disattivarlo con
<pre># a2dismod nome_modulo</pre>
<pre># a2dismod nome_modulo</pre>
== Certificati SSL (https) ==
Come già accennato in precedenti sezioni di questa guida è necessario installare un certificato SSL perché un certo sito internet possa essere servito tramite protocollo <code>https</code>.<br>
Per webserver esclusivamente operanti nella propria LAN è possibile creare e firmare manualmente tutti i certificati che si vogliono, mentre se si vuole ottenere un certificato per un dominio pubblico (già in possesso dell'utente) è necessario farne richiesta ad una ''certificate authority'' (CA).<br>
In entrambi i casi le operazioni da effettuare non sono esattamente banali, grazie al lavoro di due fondazioni senza scopo di lucro è stato perfezionato uno strumento che permette di ottenere certificati SSL (compresi i cosidetti ''wildcard certificates'') in maniera gratuita e notevolmente semplificata. La fondazioni sono la ''Electronic Frontier Foudation'' responsabile dello sviluppo dello strumento <code>certbot</code> e ''let's encrypt'' che fornisce gratuitamente i certificat SSL.
=== Certbot ===
<br/>
{{Box|IMPORTANTE|EFF consiglia ora di installare <code>certbot</code> usando <code>snapd</code> (vedere la [https://certbot.eff.org/ pagina dedicata] di EFF).}}
==== Premessa ====
Nel seguito di questa sezione si faranno le seguenti ipotesi:
* l'utente ha le porte standard, ovvero '''80''' e '''443''', aperte anche in ingresso. In caso contrario molti degli automatismi dello strumento andrebbero persi e la procedura standard non sarebbe più applicabile. Da notare che i propri virtualhost possono usare qualsiasi porta, ovvero non sono obbligati ad usare le porte standard, è semplicemente <code>certbot</code> che richiede che dette porte siano aperte per funzionare correttamente;
* l'utente ha già configurato il proprio eventuale firewall di rete in modo da reindirizzare correttamente le succitate porte.
* l'utente non è interessato ad ottenere ''wild certificates'', cioè un certificato che copra tutti i possibili sottodomini (tipo ''*.mio_dominio.abc'').
==== Installazione e configurazione ====
Per prima cosa è necessario installare i seguenti pacchetti
<pre># apt install certbot python-certbot-apache</pre>
quindi attivare i seguenti moduli:
<pre># a2enmod a2enmod headers ssl</pre>
Se tutto quanto scritto in precedenza è andato a buon fine allora è possibile digitare un comando del tipo
<pre># certbot --apache -d ind1.mio_dominio.abc,ind2.mio_dominio.abc,ind3.mio_dominio.abc ...</pre>
dove l'utente specifica tutti i domini che vuole siano coperti da un unico certificato.
{{Box|IMPORTANTE|Tutti i domini specificati devono essere stati dichiarati ciascuno come <code>ServerName</code> di un diverso virtualhost.}}
Nel caso di singolo dominio e riprendendo l'esempio fatto precedentemente il comando diviene
<pre># certbot -d ind1.mio_dominio.abc</pre>
Lo strumento proporrà innanzitutto tre domande
<pre>
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel):
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o:
</pre>
Dopo di che se la configurazione è andata a buon fine restituirà qualcosa di simile a
<pre>
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for ind1.mio_dominio.abc
Enabled Apache rewrite module
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/mio_sito-le-ssl.conf
Deploying Certificate to VirtualHost /etc/apache2/sites-available/mio_sito-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/mio_sito-le-ssl.conf
</pre>
e quindi porrà la seguente domanda:
<pre>
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.                                           
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -                                                 
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for                                                 
new sites, or if you're confident your site works on HTTPS. You can undo this                                                   
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -                                                 
Select the appropriate number [1-2] then [enter] (press 'c' to cancel):
</pre>
Se si risponde uno sarà onere dell'utente modificare opportunamente i file conf del proprio sito web, viceversa rispondendo "2" sarà visualizzato qualcosa di simile a quanto segue:
<pre>
Enabled Apache rewrite module                                                                                                   
Redirecting vhost in /etc/apache2/sites-enabled/mio_sito.conf to ssl vhost in /etc/apache2/sites-available/mio_sito-le-ssl.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://ind1.mio_dominio.abc
You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=ind1.mio_dominio.abc
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
  /etc/letsencrypt/live/ind1.mio_dominio.abc/fullchain.pem
  Your key file has been saved at:
  /etc/letsencrypt/live/ind1.mio_dominio.abc/privkey.pem
  Your cert will expire on 2019-08-24. To obtain a new or tweaked
  version of this certificate in the future, simply run certbot again
  with the "certonly" option. To non-interactively renew *all* of
  your certificates, run "certbot renew"
- If you like Certbot, please consider supporting our work by:
  Donating to ISRG / Let's Encrypt:  https://letsencrypt.org/donate
  Donating to EFF:                    https://eff.org/donate-le
</pre>
Si supponga ora che il file conf di partenza fosse:
<pre>
<VirtualHost *:80>
ServerName ind1.ciao.abc
DocumentRoot "/var/www/cartella_mio_sito/"
DirectoryIndex pagina_principale.html
</VirtualHost>
</pre>
Al termine delle operazione il file di partenza <code>mio_sito.conf</code> risulterà alterato come segue:
<pre>
<VirtualHost *:80>
ServerName ind1.ciao.abc
DocumentRoot "/var/www/cartella_mio_sito/"
DirectoryIndex pagina_principale.html
        RewriteEngine on
        RewriteCond %{SERVER_NAME} =ind1.ciao.abc
        RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
</pre>
Contestualmente sarà stato creato un secondo file conf di nome <code>mio_sito-le-ssl.conf</code>:
<pre>
<IfModule mod_ssl.c>
    <VirtualHost *:443>
        ServerName ind1.ciao.abc
        DocumentRoot "/var/www/cartella_mio_sito/"
        DirectoryIndex pagina_principale.html
        SSLCertificateFile /etc/letsencrypt/live/ind1.ciao.abc/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/ind1.ciao.abc/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf
    </VirtualHost>
</IfModule>
</pre>
In sintesi quello che succede è che il file di conf originale, cioè <code>mio_sito.conf</code>, viene modificato in modo da reindirizzare tutte le richieste dirette al virtualhost configurato sulla porta 80 a quello sulla porta 443, ovvero ogni richiesta http viene automaticamente convertita in una https.<br>
Se non si avesse alcun interesse a mantenere il virtualhost sulla porta 80 si può disabilitare/eliminare il file <code>mio_sito.conf</code> senza problemi, tuttavia è bene sapere che tutte le richieste http non verranno più inoltrate automaticamente su https, quindi l'utente si vedrà restituire dal webserver un errore ''403 Forbidden'' (è quindi fondamentale che chi già fruiva in precedenza del sito sia informato del cambio).
==== Rinnovo dei certificati ====
Certbot permette di rinnovare in automatico tutti i propri certificati con il comando <code>certbot renew</code>. Per testare subito che il predetto comando funzioni è possibile usare l'opzione <code>--dry-run</code>, ovvero:
<pre># certbot renew --dry-run</pre>
che in caso di successo dovrebbe restituire qualcosa di simile a:
<pre>
Saving debug log to /var/log/letsencrypt/letsencrypt.log
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/ind1.mio_dominio.abc.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert not due for renewal, but simulating renewal for dry run
Plugins selected: Authenticator apache, Installer apache
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for ind1.mio_dominio.abc
Waiting for verification...
Cleaning up challenges
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
new certificate deployed with reload of apache server; fullchain is
/etc/letsencrypt/live/ind1.mio_dominio.abc/fullchain.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
** DRY RUN: simulating 'certbot renew' close to cert expiry
**          (The test certificates below have not been saved.)
Congratulations, all renewals succeeded. The following certs have been renewed:
  /etc/letsencrypt/live/ind1.mio_dominio.abc/fullchain.pem (success)
** DRY RUN: simulating 'certbot renew' close to cert expiry
**          (The test certificates above have not been saved.)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IMPORTANT NOTES:
- Your account credentials have been saved in your Certbot
  configuration directory at /etc/letsencrypt. You should make a
  secure backup of this folder now. This configuration directory will
  also contain certificates and private keys obtained by Certbot so
  making regular backups of this folder is ideal.
</pre>
A questo punto è possibile automatizzare il processo di rinnovo inserendo in [[Utilizzo del servizio di scheduling Cron | crontab]] il comando <code>certbot renew -q</code>, visto che i certificati '''NON''' saranno rinnovati a meno che non siano prossimi alla scadenza (l'opzione <code>-q</code> permette di sopprimere l'output del comando, fatta eccezione per eventuali errori).<br>
Per esempio volendo ripetere la verifica ogni 10 del mese alla 1:30 la riga da inserire in [[Utilizzo del servizio di scheduling Cron | crontab]] sarebbe:
<pre>30 1 10 * * /usr/bin/certbot renew -q</pre>
==== Errori ====
===== Apache non raggiungibile =====
Se per una qualsiasi ragione il proprio webserver non risultasse raggiungibile dall'esterno la pocedurà fallirà mostrando qualcosa di simile a quanto segue:
<pre>
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for mio_dominio.abc
http-01 challenge for ind1.mio_dominio.abc
Enabled Apache rewrite module
Waiting for verification...
Cleaning up challenges
Failed authorization procedure. mio_dominio.abc (http-01): urn:ietf:params:acme:error:connection :: The server could not connect to the client to verify the domain :: Fetching http://mio_dominio.abc/.well-known/acme-challenge/stringa_di_vari_caratteri: Connection refused, ind1.mio_dominio.abc (http-01): urn:ietf:params:acme:error:connection :: The server could not connect to the client to verify the domain :: Fetching http://ind1.mio_dominio.abc/.well-known/acme-challenge/stringa_di_vari_caratteri: Connection refused
IMPORTANT NOTES:
- The following errors were reported by the server:
  Domain: mio_dominio.abc
  Type:  connection
  Detail: Fetching
  http://mio_dominio.abc/.well-known/acme-challenge/stringa_di_vari_caratteri:
  Connection refused
  Domain: ind1.mio_dominio.abc
  Type:  connection
  Detail: Fetching
  http://ind1.mio_dominio.abc/.well-known/acme-challenge/stringa_di_vari_caratteri:
  Connection refused
  To fix these errors, please make sure that your domain name was
  entered correctly and the DNS A/AAAA record(s) for that domain
  contain(s) the right IP address. Additionally, please check that
  your computer has a publicly routable IP address and that no
  firewalls are preventing the server from communicating with the
  client. If you're using the webroot plugin, you should also verify
  that you are serving files from the webroot path you provided.
- Your account credentials have been saved in your Certbot
  configuration directory at /etc/letsencrypt. You should make a
  secure backup of this folder now. This configuration directory will
  also contain certificates and private keys obtained by Certbot so
  making regular backups of this folder is ideal.
</pre>


== Risoluzione problemi ==
== Risoluzione problemi ==
Riga 187: Riga 424:


* [https://httpd.apache.org/ Sito ufficiale]
* [https://httpd.apache.org/ Sito ufficiale]
* [https://letsencrypt.org/ Sito Let's Encrypt]
* [https://certbot.eff.org/ Sito Certbot]




2 894

contributi