Logo
Install Nginx + Webdav on debian 11
Overview

Install Nginx + Webdav on debian 11

October 21, 2021
March 23, 2025
2 min read
Available in:

➡️ To have the necessary modules, you need to install nginx in its complete version:

Terminal window
sudo apt update && sudo apt install nginx-full
  • It’s done! Your site is accessible in your browser at the address http://IP_of_your_machine

WebDAV configuration

Tip

Create a configuration file for each site, don’t forget to change the port, to avoid having several configurations with the same port.

  • Here we will edit the default file, but we could very well copy and rename it:
Terminal window
sudo cp /etc/nginx/sites-enabled/default /etc/nginx/sites-enabled/site.conf
sudo rm /etc/nginx/sites-enabled/default

Edit the configuration file

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 The server listens on port 80.

  • Ligne 5 Defines the path of the root of the internet site (or where your index.html is, for example).

  • Ligne 18 location ^~ /webdav { says that to reach /var/www/html I enter the ip or the name of my machine + /webdav = http://172.16.30.30/webdav for example.

  • Ligne 20 Defines the path of the authentication file.

Create the authentication file

  1. Switch to root

    Terminal window
    su -
  2. Add the username

    Replace user by your username:

    Terminal window
    echo -n 'user:' | tee -a /var/www/.auth.allow
  3. Define the password

    Enter your password, confirm, it will be displayed in the form of a 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

    Check the user configuration:

    cat /var/www/.auth.allow
    cat /var/www/.auth.allow
    user_name:$apr1$9WppBYUH$L4S3jfDRXqfcAJ1mD93KD/
  4. Set file permissions

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

    Gzip compression is optional and is discouraged if the site uses https.

    Terminal window
    sed -i '/gzip_/ s/#\ //g' /etc/nginx/nginx.conf
  6. Test and restart nginx

    Terminal window
    nginx -t && systemctl restart nginx
Tip

You can connect to the webdav share (/var/www/html) using the link (http://IP_server/webdav)