% Reverse Proxy # Introduction Voir [Infrastructure du réseau sur serveur Kimsufi OVH](../proxmox/infrastructure-ovh.md) POUR GÉRER CORRECTEMENT LES CHAMPS DNS: [Gestion du DNS OVH](dns-ovh.md) # 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 < synchronisation ## Sur le reverse proxy ``` sudo adduser --shell /usr/sbin/nologin copycert sudo setfacl -R -m u:copycert:rX /etc/letsencrypt/live/ sudo setfacl -d -R -m u:copycert:rX /etc/letsencrypt/live/ sudo setfacl -R -m u:copycert:rX /etc/letsencrypt/archive/ sudo setfacl -d -R -m u:copycert:rX /etc/letsencrypt/archive/ sudo apt install rsync ``` # Dépannage{#depannage} ## Modifier le domaine principal Il faut le mettre en premier et utiliser `--force-renewal`: ```bash ./certbot --apache -d domaine-principal.fr -d www.domaine-principal.fr -d mysql.domaine-principal.fr --force-renewal ``` Voir: [cette réponse à "Change base domain name for Lets Encrypt SSL certificate"](https://stackoverflow.com/a/38268048/1011366) ## Notes supplémentaires * [reverse proxy - Nginx http to http redirect 400 The plain HTTP request was sent to HTTPS port - Server Fault](https://serverfault.com/questions/1115189/nginx-http-to-http-redirect-400-the-plain-http-request-was-sent-to-https-port) * [NGINX Error: The plain HTTP request was sent to HTTPS port - Sling Academy](https://www.slingacademy.com/article/nginx-error-the-plain-http-request-was-sent-to-https-port/) * [Dealing with nginx 400 "The plain HTTP request was sent to HTTPS port" error - Stack Overflow](https://stackoverflow.com/questions/8768946/dealing-with-nginx-400-the-plain-http-request-was-sent-to-https-port-error) * [ssl - Update certificate with certbot to add subdomain - Stack Overflow](https://stackoverflow.com/questions/55778765/update-certificate-with-certbot-to-add-subdomain)