393 words
2 minutes
Install Nginx + Webdav on debian 11
2021-10-21
2025-01-12
An issue with sudo?
Please don’t use the root account

If you configure your server directly as root, don’t forget to remove sudo from each command.
If you set a password for the root account, the sudo command won’t be accepted. Connect directly as root to execute commands.
You can also reinstall your system leaving the root password empty during installation.
sudo will install and work properly.

➡️ 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#

  • Switch to root
Terminal window
su -
  • Replace user by your username
Terminal window
echo -n 'user:' | tee -a /var/www/.auth.allow
  • Define the password of the user:
    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/

Define the permissions of the authentication file#

Terminal window
chown root:www-data /var/www/.auth.allow && chmod 640 /var/www/.auth.allow

Activate gzip compression (saves bandwidth)#

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

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

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)

Install Nginx + Webdav on debian 11
https://xsec.fr/posts/linux/nginx-webdav/
Author
Xsec
Published at
2021-10-21
License
CC BY-NC-SA 4.0