% Reverse Proxy # Introduction Voir [Infrastructure du réseau sur serveur Kimsufi OVH](../proxmox/infrastructure-ovh.html) # Installation letsencrypt cf [Certbot Instructions | Certbot](https://certbot.eff.org/instructions?ws=nginx&os=pip) ## Dépendances ```bash sudo apt update && sudo apt install python3 python3-venv libaugeas0 ``` ## Installation de `certbot` ```bash sudo python3 -m venv /opt/certbot/ sudo /opt/certbot/bin/pip install --upgrade pip sudo /opt/certbot/bin/pip install certbot certbot-nginx sudo ln -s /opt/certbot/bin/certbot /usr/bin/certbot ``` # Installation des sous-domaines ## Domaines à installer On prépare une liste des services et de leur sous-domaine associé. Par exemple, voir cette page: [Services](../../../organisation-technique/services.html) ## Configuration de `nginx` ### Chargement dans les sous-dossiers Édition de `/etc/nginx/nginx.conf` Remplacer la ligne: ```conf include /etc/nginx/sites-enabled/*; ``` Par: ```conf include /etc/nginx/sites-enabled/*/*; ``` ## Script Je crée un script d'installation qui génère automatiquement chaque fichier de configuration `nginx` pour les sous-domaines listés dans un fichier (ici par exemple: `subdomains.txt`) : ```bash $ cat ~/subdomains.txt nu.aezi.fr cloud.aezi.fr git.aezi.fr wallabag.aezi.fr appflowy.aezi.fr rustdesk.aezi.fr sync.aezi.fr pihole.aezi.fr hedgedoc.aezi.fr dessin.aezi.fr ``` ### Script `install-subdomains` **IMPORTANT**: script inspiré de ce gist: [How to use nginx as a reverse-proxy with letsencrypt · GitHub](https://gist.github.com/gmolveau/5e5b0bd2773100d85d9302d0fa96632d) **ATTENTION**: si le script ne fonctionne pas, voir la variante en dessous. ```bash #!/bin/bash set -euo pipefail if [ $EUID != 0 ] then echo "You must be root" >&2 exit 1 fi available_sites_dir=/etc/nginx/sites-available subdomains_list="${1:-}" if [ -z "${subdomains_list:-}" ] then echo "Please give me a subdomain list" exit 2 fi shift create_subdomain(){ local base_directory=$2 local subdomain_name=$1 local target_ip=$3 local main_domain=$4 if [ ! -f "$base_directory/$subdomain_name" ] then echo "Creating '$base_directory/$subdomain_name'" cat > $base_directory/$subdomain_name <