Documentation
0 - Mise en place initiale
VPS
- Aller sur PulseHeberg
- Acheter le VPS EDU-2 dans la section Education Cloud
Nom de domaine
- Acheter un nom de domaine sur OVHcloud
- Associer le domaine à l'IP publique du VPS dans la section Zone DNS
1 - Sécurité
Bonnes pratiques SSH
- Éditer le fichier de configuration SSH :
<syntaxhighlight lang="bash"> sudo nano /etc/ssh/sshd_config </syntaxhighlight>
- Modifier ou ajouter :
Port 2222 PermitRootLogin no
- Redémarrer le service :
<syntaxhighlight lang="bash"> sudo systemctl restart ssh </syntaxhighlight>
Fail2Ban
- Modifier ou créer
/etc/fail2ban/jail.local
:
<syntaxhighlight lang="ini"> [sshd] enabled = true port = 2222 filter = sshd logpath = /var/log/auth.log maxretry = 5 bantime = 3600 </syntaxhighlight>
- Redémarrer Fail2Ban :
<syntaxhighlight lang="bash"> sudo systemctl restart fail2ban </syntaxhighlight>
IPSet
- Créer une liste d'IP à bloquer :
<syntaxhighlight lang="bash"> sudo ipset create blacklist hash:ip </syntaxhighlight>
- Ajouter une règle dans iptables :
<syntaxhighlight lang="bash"> sudo iptables -I INPUT -m set --match-set blacklist src -j DROP </syntaxhighlight>
- Sauvegarder :
<syntaxhighlight lang="bash"> sudo netfilter-persistent save </syntaxhighlight>
2 - Containerisation (LXC)
Installation
<syntaxhighlight lang="bash"> sudo apt-get update sudo apt-get install lxc lxc-templates </syntaxhighlight>
Création des containers
<syntaxhighlight lang="bash"> sudo lxc-create -n nginx -t debian sudo lxc-create -n monsite -t debian </syntaxhighlight>
Configuration IP
- Container nginx :
10.0.3.10
- Container monsite :
10.0.3.101
(Fichiers : /var/lib/lxc/<nom>/rootfs/etc/network/interfaces
)
Installation des services
- Dans monsite :
<syntaxhighlight lang="bash"> sudo apt install apache2 </syntaxhighlight>
- Dans nginx :
<syntaxhighlight lang="bash"> sudo apt install nginx </syntaxhighlight>
Redirections NAT
<syntaxhighlight lang="bash"> sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 10.0.3.10:80 sudo iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT --to-destination 10.0.3.10:443 sudo iptables -t nat -A POSTROUTING -j MASQUERADE </syntaxhighlight>
Reverse Proxy
- Exemple de configuration Nginx :
<syntaxhighlight lang="nginx"> server {
listen 80; server_name monsite.exemple.com;
access_log off;
if ($request_method !~ ^(GET|HEAD|POST)$) { return 444; }
location / { proxy_pass http://10.0.3.101:80/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }
} </syntaxhighlight>
3 - Documentation (MediaWiki)
Installation
<syntaxhighlight lang="bash"> cd /tmp wget https://releases.wikimedia.org/mediawiki/1.41/mediawiki-1.41.0.tar.gz tar -xzf mediawiki-1.41.0.tar.gz sudo rm -rf /var/www/html/* sudo mv mediawiki-1.41.0/* /var/www/html/ sudo chown -R www-data:www-data /var/www/html/ sudo chmod -R 755 /var/www/html/ </syntaxhighlight>
Sécurisation
Certificat SSL
<syntaxhighlight lang="bash"> sudo apt install certbot python3-certbot-apache sudo certbot --apache -d monsite.exemple.com </syntaxhighlight>
Authentification Apache
<syntaxhighlight lang="bash"> sudo apt install apache2-utils sudo htpasswd -c /etc/apache2/.htpasswd admin </syntaxhighlight>
- Ajouter dans la configuration Apache :
<syntaxhighlight lang="apache"> <Directory "/var/www/html">
AuthType Basic AuthName "Restricted Access" AuthUserFile /etc/apache2/.htpasswd Require valid-user
</Directory> </syntaxhighlight>
- Redémarrer :
<syntaxhighlight lang="bash"> sudo systemctl restart apache2 </syntaxhighlight>
4 - Backups locaux
Script de sauvegarde
Créer /usr/local/bin/backup_mediawiki.sh
:
<syntaxhighlight lang="bash">
- !/bin/bash
BACKUP_DIR="/var/backups/mediawiki" DATE=$(date +%F) DB_NAME="nom_de_la_bdd" DB_USER="user" DB_PASS="motdepasse"
mkdir -p $BACKUP_DIR
mysqldump -u $DB_USER -p$DB_PASS $DB_NAME > $BACKUP_DIR/wiki-db-$DATE.sql
tar -czf $BACKUP_DIR/wiki-files-$DATE.tar.gz /var/www/html
find $BACKUP_DIR -type f -mtime +7 -delete </syntaxhighlight>
Crontab
Ajouter dans crontab -e
:
<syntaxhighlight lang="bash">
0 3 * * * /usr/local/bin/backup_mediawiki.sh
</syntaxhighlight>