InterspaceKnowledgebaseTech ArticlesTutorialsSetup WebDAV Server with Nginx on Linux Debian
TUTORIALS
15-Jan-202421-May-2024
Setup WebDAV Server with Nginx on Linux Debian
This guide will help you quickly set up a WebDAV server using Nginx on Debian. It is intended for users with fundamental Linux and Nginx knowledge.

Your server should already have Linux Debian (version 11 or 12) and Nginx installed from the official Debian repositories. Alternatively, consider our cloud servers offering, known as Elastic Cloud VPS, which can be deployed with a pre-installed operating system and apps in about a minute.

1.Prerequisites

Before you begin, ensure that you have the WebDAV module and nginx-extras package installed.

1.1.Install the nginx-extras package

This package contains additional modules not included in the standard Nginx installation, which are necessary for extended WebDAV functionalities. Execute the following command to install it:
sudo apt install nginx-extras

If sudo is not already installed, run apt install sudo to install it.

1.2.Check for the nginx WebDAV module

If you installed Nginx on Debian 11 or 12 using the standard package repositories (e.g., using apt install nginx), the WebDAV module, known as ngx_http_dav_module, is normally included in the installation. To check, run:
nginx -V 2>&1 | grep -o with-http_dav_module

If the module is not present, you may need to install Nginx from source or use a package that includes this module.

2.WebDAV Directories

Create directories:
sudo mkdir /var/www/webdav
sudo mkdir -p /var/tmp/nginx/webdav

Modify permissions:
sudo chown www-data:www-data /var/www/webdav
sudo chown -R www-data:www-data /var/tmp/nginx
sudo chmod -R 755 /var/tmp/nginx
sudo chmod -R 755 /var/www/webdav

3.WebDAV Access Credentials

To configure user access and set up Basic Authentication, use the following one-liner command. It prompts for a username and password, then securely adds them to the password file webdav.passwd with the password encrypted.
read -p "Enter username: " username && read -sp "Enter password: " password && echo "$username:$(openssl passwd -apr1 $password)" | sudo tee -a /etc/nginx/webdav.passwd > /dev/null && echo -e "\nCredentials added successfully."

4.Configuring Nginx for WebDAV

In your site-specific Nginx configuration file, typically located in /etc/nginx/sites-available/, within the server block, add:
location /webdav {
alias /var/www/webdav; # This maps the URL .../webdav to /var/www/webdav
client_body_temp_path /var/tmp/nginx/webdav;
dav_methods PUT DELETE MKCOL COPY MOVE;
dav_ext_methods PROPFIND OPTIONS;
create_full_put_path on;

# Basic authentication setup
auth_basic "Restricted Access";
auth_basic_user_file /etc/nginx/webdav.passwd;

# Deny all access unless authenticated
satisfy all;
allow all; # This allows all authenticated users
deny all; # This denies all other users
}

5.Additional Access Protection (Optional)

5.1.IP Restrictions

For IP-based access control, in the location /webdav section of your site-specific Nginx configuration:
allow 192.168.1.1; # Replace with your IP
deny all;

5.2.Server Tokens Configuration

In your Nginx configuration file disable server tokens:
server_tokens off;

5.3.Enhancing Security with Headers

Within the server block of your site-specific Nginx configuration, add these security headers:
add_header X-Content-Type-Options "nosniff";
add_header X-XSS-Protection "1; mode=block";
add_header X-Frame-Options "SAMEORIGIN";

6.Applying Changes

Restart Nginx to implement the new settings:
sudo systemctl restart nginx

7.Testing the Setup

To ensure that your WebDAV setup is working correctly, it is recommended to test it using WinSCP, a free SFTP, FTP, WebDAV, and SCP client for Windows.

Please keep in mind that the built-in Windows WebClient used to map a network drive to a WebDAV location will not work properly, because it requires the LOCK and UNLOCK methods, which are not supported by the native Nginx WebDAV module.

Steps to test with WinSCP
  • Download WinSCP from the official website and install it.
  • Open WinSCP. Click the New Tab button. Select "WebDAV" as the file protocol. Enter your server's URL (e.g., http://your-domain.tld/webdav) and your WebDAV username and password.
  • Click "Login" to connect.
  • Verify connectivity and WebDAV functionality by navigating through the directories, creating, modifying, and deleting files and folders.

8.Deploy with Interspace Cloud Servers

For those looking to get started quickly, the Interspace Cloud Platform offers an efficient solution. You can deploy a virtual server with pre-installed operating system and apps in about a minute. Interspace extends beyond rapid deployment by enabling you to pre-configure your systems with custom settings before the installation begins. This includes setting access details, domains, ports for connections, and other application-specific options.

In addition to rapid deployment, Interspace excels in its price-performance ratio. We invite you to explore the plans and prices on the page for Elastic Cloud VPS.
The content of this document is licensed by Interspace under the MIT License

Related content
Documentation
Cloud
Communications
Hosting
My Interspace
Tech Articles
Tutorials
Learn
News
Latest news
Latest events
Related products
Premium Internet Access
Highest-grade Internet access for professional needs. Superior point-to-point fiber-optic link, symmetrical down/up speed, unlimited traffic, SLA 99.9% and static IP. Direct connections to the top tier 1 global providers. Our network architecture is passionately designed to ensure the highest quality connections to any destination worldwide, boasting unmatched transfer speeds and multi-tier redundancy.
Dedicated Servers
Dedicated servers on high-grade hardware from well-known sever vendors. They are hosted in our own data centers, enabling us full control in safe-guarding the uptime 24/7. Selection of primary data centers and a disaster recovery one located at a safe distance. Power control options (reset, power off/on) and free of charge KVM-over-IP available 24/7 on a single click, including support to remotely boot/install your own ISO images.
Elastic Cloud VPS
Elastic Cloud VPS is a virtual machine powered by advanced cloud and networking technologies, offering significant advantages over traditional VPS hosting at an unbeatable price to performance ratio. Deploy OS and apps in just 1 min. Dynamically add or remove features. One click automatic backups, snapshots and disaster recovery replica, stored in a remote data center at a safe distance. New gen of AMD EPYC CPUs, ultra fast NVMe disks, dedicated connections and free private net.


Our website uses cookies. By continuing to use our website, you consent to the use of cookies and you agree with our Terms and conditions.    I understand