Install Nginx + Webdav on debian 11
Published on 3 min read
Updated on
Seriesgnu-linux-infrastructure
Part 4 of 6In this series22 min read in total
To have the necessary modules, you need to install nginx in its complete version:
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
- Here we will edit the default file, but we could very well copy and rename it:
sudo cp /etc/nginx/sites-enabled/default /etc/nginx/sites-enabled/site.confsudo rm /etc/nginx/sites-enabled/defaultEdit the configuration file
sudo nano /etc/nginx/sites-enabled/site.confserver { 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-3The server listens on port 80. -
Ligne 5Defines the path of the root of the internet site (or where your index.html is, for example). -
Ligne 18location ^~ /webdav {says that to reach/var/www/htmlI enterthe ip or the name of my machine+/webdav=http://172.16.30.30/webdavfor example. -
Ligne 20Defines the path of the authentication file.
Create the authentication file
Switch to root
Terminal window su -Add the username
Replace
userby your username:Terminal window echo -n 'user:' | tee -a /var/www/.auth.allowDefine 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.allowopenssl passwd -apr1 | tee -a /var/www/.auth.allow Password:Verifying - Password:$apr1$t.VOQfZL$bHLajKSa1gA34tgAVWA2l/Set file permissions
Terminal window chown root:www-data /var/www/.auth.allow && chmod 640 /var/www/.auth.allowEnable 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.confTest and restart nginx
Terminal window nginx -t && systemctl restart nginx