Logo
Installer Nginx + Webdav sur Debian 11
Overview

Installer Nginx + Webdav sur Debian 11

21 octobre 2021
23 mars 2025
2 min de lecture
Disponible en :

➡️ Pour disposer des modules nécessaires, vous devez installer nginx dans sa version complète :

Terminal window
sudo apt update && sudo apt install nginx-full
  • C’est fait ! Votre site est accessible dans votre navigateur à l’adresse http://IP_de_votre_machine

Configuration WebDAV

Tip

Créez un fichier de configuration pour chaque site, n’oubliez pas de changer le port, pour éviter d’avoir plusieurs configurations avec le même port.

  • Ici nous allons éditer le fichier par défaut, mais nous pourrions très bien le copier et le renommer :
Terminal window
sudo cp /etc/nginx/sites-enabled/default /etc/nginx/sites-enabled/site.conf
sudo rm /etc/nginx/sites-enabled/default

Éditer le fichier de configuration

Terminal window
sudo nano /etc/nginx/sites-enabled/site.conf
/etc/nginx/sites-enabled/default
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
location ^~ /webdav {
auth_basic "realm_name";
auth_basic_user_file /var/www/.auth.allow;
alias /var/www/html;
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
index file.html;
dav_methods PUT DELETE MKCOL COPY MOVE;
dav_ext_methods PROPFIND OPTIONS;
dav_access user:rw;
client_body_temp_path /var/www/tmp;
client_max_body_size 0;
create_full_put_path on;
}
}
  • Ligne 1-3 Le serveur écoute sur le port 80.

  • Ligne 5 Définit le chemin de la racine du site internet (ou où se trouve votre index.html, par exemple).

  • Ligne 18 location ^~ /webdav { dit que pour atteindre /var/www/html je saisis l'ip ou le nom de ma machine + /webdav = http://172.16.30.30/webdav par exemple.

  • Ligne 20 Définit le chemin du fichier d’authentification.

Créer le fichier d’authentification

  1. Passer en root

    Terminal window
    su -
  2. Ajouter le nom d'utilisateur

    Remplacez user par votre nom d’utilisateur :

    Terminal window
    echo -n 'user:' | tee -a /var/www/.auth.allow
  3. Définir le mot de passe

    Entrez votre mot de passe, confirmez, il sera affiché sous forme de hash.

    Terminal window
    openssl passwd -apr1 | tee -a /var/www/.auth.allow
    openssl passwd -apr1 | tee -a /var/www/.auth.allow
    Password:
    Verifying - Password:
    $apr1$t.VOQfZL$bHLajKSa1gA34tgAVWA2l/
    Tip

    Vérifiez la configuration de l’utilisateur :

    cat /var/www/.auth.allow
    cat /var/www/.auth.allow
    user_name:$apr1$9WppBYUH$L4S3jfDRXqfcAJ1mD93KD/
  4. Définir les permissions

    Terminal window
    chown root:www-data /var/www/.auth.allow && chmod 640 /var/www/.auth.allow
  5. Activer la compression gzip (optionnel)

    La compression gzip est optionnelle et est déconseillée si le site utilise https.

    Terminal window
    sed -i '/gzip_/ s/#\ //g' /etc/nginx/nginx.conf
  6. Tester et redémarrer nginx

    Terminal window
    nginx -t && systemctl restart nginx
Tip

Vous pouvez vous connecter au partage webdav (/var/www/html) en utilisant le lien (http://IP_serveur/webdav)