admin_sys

Comment créer un service apache

Point important, il faut après chaque modification redémmarrez le service apache

sudo systemctl restart apache2

Installation apache

Gestion du pare-feu

Cr�ation d’un virtual host

Pour créer un virtual host il faut créer un fichier de configuration pour apache

sudo nano /etc/apache2/sites-available/mon_domaine.conf
<VirtualHost *:80>
   ServerName doc.cclaudel.fr
   DocumentRoot /var/www/doc
</VirtualHost>

Il faut ensuite bien pensé à activer la conf du domaine

sudo a2ensite mon_domaine.conf

Gestion d’un reverse Proxy

Avoir un module reverse proxy peut être utile dans le cas d’utilisation de docker

Il faut activé les modules apache suivants

sudo a2enmod proxy
sudo a2enmod proxy_http

Dans le virtual host :

<VirtualHost *:80>
    ServerName doc.cclaudel.fr

    ProxyPreserveHost On
    ProxyPass / http://localhost:<mon_port>/
    ProxyPassReverse / http://localhost:<mon_port>/
</VirtualHost>

Certificat du site

La première étape est d’activé le module ssl pour le site web

sudo a2enmod ssl

Auto-signé (test)

sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/apache-selfsigned.key -out /etc/ssl/certs/apache-selfsigned.crt

Explication commande

Il faut ensuite modifier le fichier virtual host

<VirtualHost *:443>
   ServerName <mon_domaine>
   DocumentRoot /var/www/doc

   SSLEngine on
   SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt
   SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key
</VirtualHost>

Bien penser à mettre le port d’écoute sur 443

Let’s Encrypt (prod)

IL faut installer les paquets suivants

sudo apt-get update
sudo apt-get  install certbot python3-certbot-apache

Ensuite on fait la requête du certificat

certbot --apache -d doc.cclaudel.fr
certbot --apache -d project.cclaudel.fr
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address (used for urgent renewal and security notices)
 (Enter 'c' to cancel): lhokam.claudel@gmail.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.3-September-21-2022.pdf. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, 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: y
Account registered.
Requesting a certificate for project.cclaudel.fr

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/project.cclaudel.fr/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/project.cclaudel.fr/privkey.pem
This certificate expires on 2024-06-18.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.

Deploying certificate
Successfully deployed certificate for project.cclaudel.fr to /etc/apache2/sites-enabled/project.conf
Congratulations! You have successfully enabled HTTPS on https://project.cclaudel.fr

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Vérifier que le fichier de configuration récupère bien les certificats de let’s encrypt

<VirtualHost *:80>
    ServerName doc.cclaudel.fr
    Redirect permanent / https://doc.cclaudel.fr/
RewriteEngine on
RewriteCond %{SERVER_NAME} =doc.cclaudel.fr
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

<VirtualHost *:443>

    ServerName doc.cclaudel.fr

    ProxyPreserveHost On
    ProxyPass / http://localhost:8080/
    ProxyPassReverse / http://localhost:8080/

    SSLEngine on

    SSLCertificateFile /etc/letsencrypt/live/doc.cclaudel.fr/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/doc.cclaudel.fr/privkey.pem
    Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>

Le script crée également la tache planifié de renouvellement du certificat. La tâche est dispo sur la machine locale /etc/cron.d/certbot

Exemple de conf

  1. Avec reverse proxy + SSL autosigné

<VirtualHost *:443>
    ServerName doc.cclaudel.fr

    ProxyPreserveHost On
    ProxyPass / http://localhost:8080/
    ProxyPassReverse / http://localhost:8080/

    SSLEngine on
    SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt
    SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key
</VirtualHost>
  1. Forcer l’utilisation du ports 443 à la place du 80 ```conf

<VirtualHost *:80> ServerName doc.cclaudel.fr Redirect permanent / https://doc.cclaudel.fr/ </VirtualHost>

<VirtualHost *:443> ServerName doc.cclaudel.fr DocumentRoot /var/www/doc </VirtualHost> ```