Outils pour utilisateurs

Outils du site


admin:procedures:ajout-host-reverse-proxy-nginx

Ceci est une ancienne révision du document !


Ajout d'un host au reverse proxy

On suppose l'ajout d'un host répondant au fqdn bling.chapril.org.

Les manipulations sont à faire sur le bastion.

Doc écrite à posteriori mais pas encore testée. Merci de retirer ce bandeau lorsqu'elle sera déplombée et sans faille.

Prérequis

  • Avoir un enregistrement DNS qui résoud bling.chapril.org vers fip.chapril.org depuis l'extérieur. Typiquement un bling CNAME fip. Si ce n'est pas fait, voir ici : Ajout d'un enregistrement à la zone DNS.

Création de l'host

Définir le fichier suivant :

/etc/nginx/sites-available/bling.chapril.org
server {
    listen 80;
    listen [::]:80;
 
    server_name bling.chapril.org; 
 
    access_log /var/log/nginx/bling.chapril.org/bling.chapril.org.access_log;
    error_log /var/log/nginx/bling.chapril.org/bling.chapril.org.error_log;
 
    include /etc/nginx/acme-challenge;
}

et créer le dossier de logs :

mkdir /var/log/nginx/bling.chapril.org/

On active la configuration via un lien symbolique :

ln -sf /etc/nginx/sites-available/bling.chapril.org /etc/nginx/sites-enabled/bling.chapril.org

On teste la conf nginx :

# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

On recharge nginx :

systemctl reload nginx

Obtention d'un certificat TLS

On ajoute dans /etc/dehydrated/domains.txt :

/etc/dehydrated/domains.txt
bling.chapril.org

Puis on exécute dehydrated, notre client letsencrypt :

dehydrated -c

Le couple clé/certificat obtenu est dans /var/lib/dehydrated/certs/bling.chapril.org

Déploiement de l'host avec TLS

On ajoute une redirection systématique à la fin de la section server de la définition de l'hote dans nginx :

/etc/nginx/sites-available/bling.chapril.org
    include /etc/nginx/acme-challenge;
 
    rewrite ^(.*)$ https://$host$request_uri permanent;
 
}

Puis on définit une seconde section server écoutant sur le port 443 :

/etc/nginx/sites-available/bling.chapril.org
server {
    listen 443 ssl;
    listen [::]:443 ssl;
 
    server_name bling.chapril.org;
 
    access_log /var/log/nginx/bling.chapril.org/bling.chapril.org.access_log;
    error_log /var/log/nginx/bling.chapril.org/bling.chapril.org.error_log;
 
    ssl_certificate     /var/lib/dehydrated/certs/bling.chapril.org/fullchain.pem;
    ssl_certificate_key /var/lib/dehydrated/certs/bling.chapril.org/privkey.pem;
 
    location / {
        # remplacer par le nom de la machine qui héberge le service :
        proxy_pass http://bling;
 
        proxy_set_header Host $host;
        proxy_set_header Proxy "";
    }
}

On teste la conf nginx :

# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

On recharge nginx :

systemctl reload nginx

Et normalement l'host est fonctionnel. curl -i ou curl -I sont vos amis pour le debug.

Monitoring

Il faut impérativement penser à monitorer le service une fois terminé.

Il suffit pour cela, sur la machine admin, dans le fichier /etc/icinga2/zones.d/master/cluster/bling.conf (remplacer bling par le nom de la machine concernée) d'ajouter quelque chose comme :

/etc/icinga2/zones.d/master/cluster/bling.conf
  vars.http_vhosts["Bling page"] = {
    http_vhost = "bling.chapril.org"
    http_uri = "/"
    http_string = "<title>bling !</title>"
    http_ssl = true
  }

Si vous avez des besoins exotiques, n'hésitez pas à jeter un œil à la doc : https://docs.icinga.com/icinga2/latest/doc/module/icinga2/chapter/plugin-check-commands#plugin-check-command-http

On teste la conf :

icinga2 daemon -C

Et on reload Icinga :

/etc/init.d/icinga2 reload
admin/procedures/ajout-host-reverse-proxy-nginx.1499854379.txt.gz · Dernière modification : 2017/07/12 10:12 de fpoulain