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 13:37] – 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, and not //in**tra**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 |
- | [[https:// | + | You will be using your SSO authentication, |
- | [[https:// | + | In the past i used a more complex solution leveraging more tools. That obsolete solution has been moved, for reference, |
- | [[sailing: | + | ===== Overall Architecture |
+ | This solution leverages the use of one tool called AList (installation & configuration instructions [[services: | ||
- | ===== Permissions and Users ===== | + | AList itself also support SSO integration, |
- | All users need to be in the **users** group. | + | You can also define as many shared folders as you like, and even connect |
- | The **common** share will be accessible | + | I will assume that your shares are under **/ |
- | ===== Shares Configuration ===== | + | Each share folder will have the following structure: |
+ | * / | ||
+ | * / | ||
+ | * / | ||
- | Files will be under **/ | + | Your AList installation |
- | <file txt shares> | + | |
- | SHARES=" | + | |
- | </ | + | |
- | where " | + | I choose to assign a dedicated subdomain, **drive.mydomain.com**, |
+ | * **https:// | ||
+ | | ||
+ | * **https:// | ||
+ | * **https:// | ||
+ | * **https:// | ||
+ | * **https:// | ||
+ | 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. | ||
- | ===== Software Installation for Browser access ===== | + | You can add any more folders as separate shares as you like. Due to how WebDAV works, it is mandatory to separate the browser accessible URLs from the WebDAV ones, like i did above. |
- | [[https:// | ||
- | 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. | + | === Permissions and Users === |
- | first you need to create a new user: | + | (Note: |
- | <code bash> | + | |
- | > useradd -d / | + | |
- | </ | + | |
- | the // | + | I assume you have already created |
- | You will need to create the following folders architecture in your // | + | You need to set the //umask// for the fileserver |
- | * bin: where the FileBrowser binary will be located | + | |
- | * data/db: where the FileBrowser databases files will be stored | + | |
- | * data/logs: where the various log files will be created | + | |
- | + | ||
- | 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. | + | |
- | + | ||
- | Then, as // | + | |
<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. | ||
- | ===== Software Installation for WebDAV | + | ===== Fileserver |
- | While there are a few WebDAV servers like [[https:// | + | Nothing extra needs to be done except install AList, and adding the new shares inside |
- | The idea here is to run a dedicated copy of Apache as user // | ||
- | <code bash> | ||
- | > emerge apache | ||
- | </ | ||
- | WebDAV is enabled by default in Gentoo Apache ebuild. | ||
- | Running apache manually requires some effort, so, buckle up. | + | ===== Fileserver access via WebDAV ===== |
- | First of all, Apache needs some folders | + | __NOTE:__ using HTTP will cause a 301 redirect |
- | * / | + | |
- | * / | + | |
- | * / | + | |
- | * / | + | |
- | <code bash> | + | The only chnage |
- | > su - filebrowser | + | < |
- | > mkdir / | + | |
- | > mkdir / | + | |
- | </ | + | |
- | + | | |
- | Then create the Apache config file for each share. You should create this config that will be used by each share **/ | + | |
- | <file txt apache_global.conf> | + | |
- | ServerRoot "/ | + | |
- | LoadModule actions_module modules/ | + | |
- | LoadModule alias_module modules/ | + | proxy_redirect |
- | LoadModule auth_basic_module modules/ | + | |
- | LoadModule authn_anon_module modules/ | + | |
- | LoadModule authn_core_module modules/ | + | |
- | LoadModule authn_dbm_module modules/ | + | |
- | LoadModule authn_file_module modules/ | + | |
- | LoadModule authz_core_module modules/ | + | |
- | LoadModule authz_dbm_module modules/ | + | |
- | LoadModule authz_groupfile_module modules/ | + | |
- | LoadModule authz_host_module modules/ | + | |
- | LoadModule authz_owner_module modules/ | + | |
- | LoadModule authz_user_module modules/ | + | |
- | LoadModule autoindex_module modules/ | + | |
- | < | + | |
- | LoadModule cache_module modules/ | + | |
- | </ | + | |
- | LoadModule dav_module modules/ | + | |
- | LoadModule dav_fs_module modules/ | + | |
- | LoadModule dav_lock_module modules/ | + | |
- | LoadModule deflate_module modules/ | + | |
- | LoadModule dir_module modules/ | + | |
- | LoadModule env_module modules/ | + | |
- | LoadModule expires_module modules/ | + | |
- | LoadModule ext_filter_module modules/ | + | |
- | < | + | |
- | LoadModule file_cache_module modules/ | + | |
- | </ | + | |
- | LoadModule filter_module modules/ | + | |
- | LoadModule headers_module modules/ | + | |
- | < | + | |
- | LoadModule http2_module modules/ | + | |
- | </ | + | |
- | LoadModule include_module modules/ | + | |
- | < | + | |
- | LoadModule info_module modules/ | + | |
- | </ | + | |
- | LoadModule log_config_module modules/ | + | |
- | TransferLog / | + | |
- | LoadModule logio_module modules/ | + | |
- | LoadModule mime_module modules/ | + | |
- | LoadModule mime_magic_module modules/ | + | |
- | LoadModule negotiation_module modules/ | + | |
- | LoadModule rewrite_module modules/ | + | |
- | LoadModule setenvif_module modules/ | + | |
- | < | + | |
- | LoadModule status_module modules/ | + | |
- | </ | + | |
- | LoadModule unique_id_module modules/ | + | |
- | LoadModule unixd_module modules/ | + | |
- | < | + | |
- | LoadModule userdir_module modules/ | + | |
- | </ | + | |
- | LoadModule usertrack_module modules/ | + | |
- | LoadModule vhost_alias_module modules/ | + | |
- | Include / | + | |
- | </ | + | |
- | + | ||
- | Then you can create one config file for each share. This is the file for the common share **/ | + | |
- | <file txt common.conf> | + | |
- | Include / | + | |
- | + | ||
- | User filebrowser | + | |
- | Group users | + | |
- | + | ||
- | DavLockDB "/ | + | |
- | PidFile / | + | |
- | ErrorLog / | + | |
- | TransferLog / | + | |
- | CustomLog / | + | |
- | + | ||
- | DocumentRoot / | + | |
- | + | ||
- | ServerName 127.0.0.1 | + | |
- | Listen 127.0.0.1: | + | |
- | + | ||
- | < | + | |
- | DAV On | + | |
- | AllowOverride All | + | |
- | Options -Indexes +FollowSymlinks -ExecCGI -Includes | + | |
- | Require all granted | + | |
- | </ | + | |
- | + | ||
- | SetEnv redirect-carefully | + | |
- | + | ||
- | # vim: ts=4 filetype=apache | + | |
- | </ | + | |
- | + | ||
- | Now, the fun part is that you want to protect this behind | + | |
- | + | ||
- | Since you will be exposing the browser-based access as **https:// | + | |
- | + | ||
- | < | + | |
- | > su - filebrowser | + | |
- | > cd data/root | + | |
- | > mkdir webdav | + | |
- | > cd webdav | + | |
- | > ln -s / | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | xxxxxx | + | |
- | + | ||
- | + | ||
- | + | ||
- | Now, reverse proxy is simple, but this into **/ | + | |
- | <file txt filebrowser.conf> | + | |
- | + | ||
- | location / | + | |
- | | + | |
- | + | ||
- | | + | |
- | | + | |
- | + | ||
- | | + | |
- | 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 | + | |
- | su - $OWNER -c " | + | |
- | done | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | And the usual autostart stuff: | + | |
- | <file bash 40-filebrowser.start> | + | |
- | # | + | |
- | / | + | |
- | </ | + | |
- | + | ||
- | Make both files executable. | + | |
- | + | ||
- | + | ||
- | + | ||
- | ===== 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: | + | |
- | + | ||
- | + | ||
- | + | ||