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 14:14] – 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 |
- | * / | + | |
- | * / | + | |
- | * / | + | |
- | * / | + | |
- | < | + | The only chnage you need to make is to add the following location to the NGINX configuration file you created during AList setup: |
- | > su - filebrowser | + | < |
- | > mkdir /data/daemons/ | + | |
- | > mkdir /data/daemons/filebrowser/data/root | + | proxy_pass http://127.0.0.1: |
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
</ | </ | ||
- | Then create the Apache config file for each share. You should create this config that will be used by each share **/ | + | which will remap /webdav to /dav |
- | <file txt apache_global.conf> | + | |
- | ServerRoot "/ | + | |
- | LoadModule actions_module modules/ | + | |
- | LoadModule alias_module modules/ | + | |
- | 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 | + | |
- | </ | + | |
- | + | ||
- | Please note the Listen directive: you want apache to be bound to 127.0.0. only and note the port too, this port will be needed for the reverse proxy. Each share will need it's own port. | + | |
- | + | ||
- | Now, the fun part is that you want to protect this behind the NGINX reverse proxy and it seems that WebDAV does **not** play well with URL redirection and similar funny things. In other words, the base url you will be using on the reverse proxy must match the url in the Apache. You cannot use rewrite directives or Alias stuff. | + | |
- | + | ||
- | Since you will be exposing the browser-based access as **https:// | + | |
- | + | ||
- | so, create the paths first: | + | |
- | <code bash> | + | |
- | > su - filebrowser | + | |
- | > cd data/root | + | |
- | > mkdir webdav | + | |
- | > cd webdav | + | |
- | > mkdir common | + | |
- | </ | + | |
- | + | ||
- | the startup script below will take take of doing the **mount -o bind** which is mandatory for WebDAV to work. | + | |
- | + | ||
- | + | ||
- | ===== Reverse Proxy ===== | + | |
- | + | ||
- | You want to integrate all this into the SSL enabled reverse proxy, which is also using PAM authentication. | + | |
- | + | ||
- | Now, reverse proxy is simple, but this into **/ | + | |
- | <file txt filebrowser.conf> | + | |
- | # Browser based access here | + | |
- | location / | + | |
- | client_max_body_size 512M; | + | |
- | + | ||
- | proxy_pass http:// | + | |
- | proxy_http_version 1.1; | + | |
- | + | ||
- | proxy_set_header Connection $http_connection; | + | |
- | proxy_set_header Connection ' | + | |
- | proxy_cache_bypass $http_upgrade; | + | |
- | proxy_set_header Host $host; | + | |
- | proxy_set_header X-Real-IP $remote_addr; | + | |
- | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | + | |
- | proxy_set_header X-Forwarded-Proto $scheme; | + | |
- | } | + | |
- | # WebDAV access | + | |
- | location | + | |
- | # https:// | + | |
- | # https:// | + | |
- | set $dest $http_destination; | + | |
- | if ($http_destination ~ " | + | |
- | set $dest http:// | + | |
- | } | + | |
- | + | ||
- | proxy_pass http:// | + | |
- | proxy_redirect off; | + | |
- | proxy_buffering off; | + | |
- | gzip off; | + | |
- | proxy_pass_request_headers on; | + | |
- | proxy_set_header Destination | + | |
- | proxy_set_header | + | |
- | proxy_set_header | + | |
- | proxy_set_header | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | and put this file include inside the usual **/ | + | |
- | + | ||
- | ===== Wrapup and Autostart ===== | + | |
- | + | ||
- | Create the **/ | + | |
- | <file bash fileserver.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 Mounting WebDAV entry points for $SHARE | + | |
- | mount -o bind / | + | |
- | 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. | + | |
- | + | ||
- | To access via browser: open https://< | + | |
- | + | ||
- | to access via WebDAV clients: https://<your server>/ | + | |
- | + | ||
- | Please note that using HTTP here might cause a 301 redirect to HTTPS, and WebDAV clients will fail. So use HTTPS URL in webdav clients. | + | |
- | + | ||
- | + | ||
- | + | ||