Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| selfhost:fileserver [2024/01/18 10:56] – willy | selfhost:fileserver [2025/03/19 15:09] (current) – willy | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== File Server ====== | + | ====== |
| + | I will not discuss how to share your files on the home network using __legacy__ tools like [[https:// | ||
| - | Access | + | I will focus on how to provide access via __web browser__ and via __WebDAV__, which is a web-based sharing protocol a bit like NFS or SAMBA, but aimed ad broader //in**ter**net// access, |
| - | Access must be both from web page (HTTP/ | + | The idea is to create share areas where your users will be able to store files. It is possible to extend this idea also to user-specific areas where each user can put private stuff not visible by other users, but this require a little bit extra complexity |
| - | [[sailing: | + | You will be using your SSO authentication, |
| - | [[sailing:NGINX]] is used as WebDAV server. | + | In the past i used a more complex solution leveraging more tools. That obsolete solution has been moved, for reference, |
| - | ===== Permissions | + | ===== Overall Architecture |
| - | All users need to be in the **users** group. | + | This solution leverages the use of one tool called AList (installation & configuration instructions [[services: |
| - | The **common** share will be accessible by any user in the **users** group. | + | AList itself also support SSO integration, |
| - | ===== Shares Configuration ===== | + | You can also define as many shared folders as you like, and even connect to remote services from the same UI. |
| - | Files will be under **/home/common** for example. The shares | + | I will assume that your shares are under **/data/shares**, but of course each share can be located anywhere you like. Let's also assume, as an example, that your share is called __/ |
| - | <file txt shares> | + | |
| - | SHARES=" | + | |
| - | </ | + | |
| - | where " | + | Each share folder |
| + | | ||
| + | | ||
| + | | ||
| + | Your AList installation will provide WebDAV and browser access from one single port hwich need to be reverse-proxied. | ||
| - | ===== Software Installation | + | I choose to assign a dedicated subdomain, **drive.mydomain.com**, |
| + | * **https:// | ||
| + | * **https:// | ||
| + | * **https:// | ||
| + | * **https:// | ||
| + | * **https:// | ||
| + | * **https:// | ||
| - | [[https://filebrowser.org/|File Browser]] is a nice web-based file manager that you can use to access your file server via browser. | + | I think that /webdav is easier to remember than /dav, but AList by default shared WebDAV under /dav, NGINX will be used to map the /webdav path to /dav. |
| - | I do not like the default installation method because it will install system-wide. I will show you how to install in a more customized way. | + | You can add any more folders as separate shares as you like. Due to how WebDAV works, it is mandatory |
| - | first you need to create a new user: | ||
| - | <code bash> | ||
| - | > useradd -d / | ||
| - | </ | ||
| - | the // | + | === Permissions |
| - | You will need to create the following folders architecture in your filebrowser home folder: | + | (Note: you should run AList as the user **fileserver** and group **users**) |
| - | * bin: where the FileBrowser binary will be located | + | |
| - | | + | |
| - | | + | |
| - | You need to set the //umask// for the user to **0002** so that any new files created by it will be writable by the users. | + | I assume you have already created |
| - | Then, as //filebrowser// user, get the software package and decompress | + | You need to set the //umask// for the fileserver |
| <code bash> | <code bash> | ||
| - | > su - filebrowser | + | mkdir /data/shares |
| - | > echo "umask 0002" >> ~/.bashrc | + | mkdir /data/shares/ |
| - | > source ~/.bashrc | + | chown fileserver: |
| - | > mkdir bin data data/logs data/db | + | |
| - | > cd bin | + | |
| - | > tar xvf ../linux-amd64-filebrowser.tar.gz | + | |
| </ | </ | ||
| - | Now, you will need to start a copy of FileBrowser for each share you want to have, and it must be owned by the user that want file permissions on that share. | ||
| - | To achieve this, you will be using a special script called **fileserver.sh** which i will show you at the end, because it will contain also the WebDAV start stuff in it. | + | ===== Fileserver access via Browser ===== |
| - | ===== Software Installation for WebDAV access ===== | + | Nothing extra needs to be done except install AList, and adding the new shares inside it's WEB configuration. |
| + | ===== Fileserver access via WebDAV ===== | ||
| + | __NOTE:__ using HTTP will cause a 301 redirect to HTTPS, and WebDAV clients will fail. So use HTTPS URL in webdav clients and not HTTP. | ||
| - | + | The only chnage | |
| - | + | <code> | |
| - | + | location /webdav/ { | |
| - | + | | |
| - | + | | |
| - | + | | |
| - | + | | |
| - | + | | |
| - | + | | |
| - | + | | |
| - | + | proxy_redirect | |
| - | + | | |
| - | + | ||
| - | since it will be hidden behind the reverse proxy, | + | |
| - | + | ||
| - | You need to setup filebrowser | + | |
| - | <code bash> | + | |
| - | > mkdir / | + | |
| - | > mkdir / | + | |
| - | > chown -R filebrowser: | + | |
| - | </ | + | |
| - | + | ||
| - | Now, a startup script: | + | |
| - | <file bash filebrowser.sh> | + | |
| - | # | + | |
| - | cd / | + | |
| - | ./ | + | |
| - | </ | + | |
| - | + | ||
| - | And the usual autostart stuff: | + | |
| - | <file bash 40-filebrowser.start> | + | |
| - | # | + | |
| - | start-stop-daemon -b -m -p / | + | |
| - | </ | + | |
| - | + | ||
| - | Make both files executable. | + | |
| - | + | ||
| - | Now, reverse proxy is simple, but this into **/ | + | |
| - | <file txt filebrowser.conf> | + | |
| - | + | ||
| - | | + | |
| - | | + | |
| - | + | ||
| - | | + | |
| - | | + | |
| - | + | ||
| - | | + | |
| - | proxy_set_header | + | |
| - | proxy_cache_bypass | + | |
| - | proxy_set_header Host $host; | + | |
| - | proxy_set_header X-Real-IP $remote_addr; | + | |
| - | proxy_set_header | + | |
| - | proxy_set_header | + | |
| - | } | + | |
| - | </ | + | |
| - | + | ||
| - | and put this file include inside the usual **/ | + | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | <file bash filebrowser.sh> | + | |
| - | source / | + | |
| - | + | ||
| - | BASE_PATH=/ | + | |
| - | + | ||
| - | for i in $SHARES | + | |
| - | do | + | |
| - | SHARE=$(echo $i | cut -d: -f1) | + | |
| - | PORT=$(echo $i | cut -d: -f2) | + | |
| - | OWNER=filebrowser | + | |
| - | + | ||
| - | echo Starting FileBrowser for $OWNER on share $SHARE | + | |
| - | su - $OWNER -c "/ | + | |
| - | su - $OWNER -c "/ | + | |
| - | + | ||
| - | echo Starting WebDAV backend for $OWNER on share $SHARE | + | |
| - | done | + | |
| - | </ | + | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | ===== Background ===== | + | |
| - | + | ||
| - | From users point of view, the common area will be managed by user **filebrowser** which is designed to run as group **users** with an //umask// 550 so that any files uploaded via web browser will be accessible to the normal users. | + | |
| - | + | ||
| - | Of course, each user will need to be part of the **users** group as well. | + | |
| - | + | ||
| - | You will need a common " | + | |
| - | + | ||
| - | This folder will need to contain: | + | |
| - | * **common** subfolder, where the common area files will be stored (created in the [[sailing: | + | |
| - | * **temp/ | + | |
| - | * **temp/ | + | |
| - | * **temp/ | + | |
| - | * **logs** subfolder, to store NGINX log files | + | |
| - | * **conf** subfolder, where you will store custom NGINX config files for the private areas (and common area too) | + | |
| - | + | ||
| - | Create the folders: | + | |
| - | <code bash> | + | |
| - | > mkdir / | + | |
| - | > mkdir / | + | |
| - | > mkdir / | + | |
| - | > mkdir / | + | |
| - | > mkdir / | + | |
| - | > mkdir / | + | |
| - | > mkdir / | + | |
| - | > chown filebrowser: | + | |
| - | </ | + | |
| - | + | ||
| - | ===== NGINX WebDAV approach ===== | + | |
| - | + | ||
| - | No need to use third party WebDAV server since NGINX has a pretty solid implementation of it already. Follow the [[sailing: | + | |
| - | + | ||
| - | Now, there is a nasty catch here which stems from using NGINX as WebDAV server... You need to run NGINX as // | + | |
| - | + | ||
| - | For consistency, | + | |
| - | <file txt / | + | |
| - | worker_processes 1; | + | |
| - | pid / | + | |
| - | error_log / | + | |
| - | + | ||
| - | events { | + | |
| - | worker_connections 100; | + | |
| - | use epoll; | + | |
| - | } | + | |
| - | + | ||
| - | http { | + | |
| - | include / | + | |
| - | default_type application/ | + | |
| - | + | ||
| - | # These folder MUST be redirected to avoid usage of system wide ones: | + | |
| - | client_body_temp_path | + | |
| - | proxy_temp_path | + | |
| - | fastcgi_temp_path | + | |
| - | uwsgi_temp_path | + | |
| - | scgi_temp_path | + | |
| - | disable_symlinks | + | |
| - | + | ||
| - | keepalive_timeout 75 20; | + | |
| - | + | ||
| - | server { | + | |
| - | server_name 127.0.0.1; | + | |
| - | + | ||
| - | access_log / | + | |
| - | location / { | + | |
| - | root / | + | |
| - | + | ||
| - | dav_methods PUT DELETE MKCOL COPY MOVE; | + | |
| - | dav_ext_methods PROPFIND OPTIONS; | + | |
| - | dav_access user:rw group:rw all:r; | + | |
| - | + | ||
| - | | + | |
| - | create_full_put_path on; | + | |
| - | client_body_temp_path / | + | |
| - | } | + | |
| - | listen 10000; | + | |
| } | } | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | This NGINX server will listen on 127.0.0.1: | ||
| - | <file txt webdav.conf> | ||
| - | location ~ ^/ | ||
| - | rewrite / | ||
| - | proxy_pass http:// | ||
| - | } | ||
| - | </ | ||
| - | and including it into the main NGINX server. | ||
| - | |||
| - | Now, edit the **/ | ||
| - | < | ||
| - | nginx -c / | ||
| </ | </ | ||
| - | like this: | + | which will remap /webdav to /dav |
| - | <file bash filebrowser.sh> | + | |
| - | #!/bin/bash | + | |
| - | + | ||
| - | cd / | + | |
| - | nginx -c / | + | |
| - | ./ | + | |
| - | </ | + | |
| - | + | ||
| - | and restart filebrwoser and the main NGINX. | + | |
| - | + | ||
| - | At this point, your common area will be ready and working both on WebDAV and directly via web browser. | + | |
| - | + | ||
| - | To access via browser: | + | |
| - | + | ||
| - | to access via WebDAV clients: | + | |
| - | + | ||
| - | + | ||
| - | + | ||