Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
services:fileserver [2024/04/09 08:38] – willy | services:fileserver [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== File Server ====== | ||
- | |||
- | In order to access your files from everywhere you need the following access vectors: | ||
- | * From a web browser (to access anywhere) | ||
- | * Via WebDAV (to access from apps and phone) | ||
- | * Using NFS (to access from Linux) | ||
- | * Using SMB (to access from Windows) | ||
- | |||
- | It is not possible to achieve all this using one single tool, so you will need to leverage different pieces together, and i will show yo how. | ||
- | |||
- | The idea is to create one share area 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 and might be addressed in the future. | ||
- | |||
- | You will be using your home server authentication, | ||
- | |||
- | ===== Shares Configuration ===== | ||
- | |||
- | Let's assume you will need one common share, called with lots of imagination **common**, and the files will be under **/ | ||
- | |||
- | You will also need to pick a free port on your server, let's assume your port 3002 is available, which will be needed for NGINX reverse proxy access via browser. | ||
- | |||
- | === Permissions and Users === | ||
- | |||
- | All users which need to access the shares must be in the **users** group: the **common** share will be accessible by any user in the **users** group. | ||
- | |||
- | You will also need to add a specific **fileserver** user to run the associated services, then go ahead and create the **/ | ||
- | <code bash> | ||
- | useradd -d / | ||
- | mkdir / | ||
- | chown fileserver: | ||
- | </ | ||
- | |||
- | ===== Fileserver access via Browser ===== | ||
- | |||
- | I strongly recomend to use [[services: | ||
- | |||
- | // | ||
- | - 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. | ||
- | |||
- | I assume you have installed FileBrowser as indicated above (you should skip the Reverse Proxy instructions that will be specified later on here). Then: | ||
- | <code bash> | ||
- | su - fileserver | ||
- | echo "umask 0002" >> ~/.bashrc | ||
- | source ~/.bashrc | ||
- | mkdir data data/logs data/db | ||
- | </ | ||
- | |||
- | 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. | ||
- | |||
- | In order to start FileBrowser at boot, i assume you are ofllowing my [[gentoo: | ||
- | <code bash> | ||
- | cd / | ||
- | ln -s _servicer.sh 39-filebrowser--service.start | ||
- | ln -s _servicer.sh 39-filebrowser--service.stop | ||
- | </ | ||
- | |||
- | ===== Fileserver access via WebDAV ===== | ||
- | |||
- | While there are a few WebDAV servers like [[https:// | ||
- | |||
- | Also NGINX can be a WebDAV server, but it seems to be buggy and not supporting LOCK stuff, so i decided to go with Apache web server, which also has a long standing WebDAV implementation. | ||
- | |||
- | 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, so need to fix USE flags. | ||
- | |||
- | Running apache manually, and not as a system service, requires some effort, so, buckle up! | ||
- | |||
- | === Running Apache as local user === | ||
- | First of all, Apache needs some folders to operate, so you need to create: | ||
- | * / | ||
- | * / | ||
- | * / | ||
- | * / | ||
- | |||
- | <code bash> | ||
- | su - fileserver | ||
- | mkdir / | ||
- | mkdir / | ||
- | mkdir / | ||
- | mkdir / | ||
- | </ | ||
- | |||
- | Then create the global Apache config file for all the shares. You should create this config that will be used by each share **/ | ||
- | |||
- | <file - 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/ | ||
- | |||
- | # This is needed to avoid error on load due to default path being not accessible | ||
- | 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 - common.conf> | ||
- | Include / | ||
- | |||
- | User fileserver | ||
- | 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 // | ||
- | |||
- | === Messing with the WebDAV root folder === | ||
- | |||
- | Now, the fun part is that you want to protect this behind the NGINX reverse proxy (for HTTPS and authorization reasons) 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 - fileserver | ||
- | cd / | ||
- | mkdir webdav | ||
- | cd webdav | ||
- | mkdir common | ||
- | </ | ||
- | |||
- | To start Apache, and mount the needed shares, you can create the **/ | ||
- | <file - apache_start.sh> | ||
- | #!/bin/bash | ||
- | # Bind/Mount the share for Apache | ||
- | if [ " | ||
- | then | ||
- | mount -o bind / | ||
- | fi | ||
- | su - filebrowser -c " | ||
- | </ | ||
- | |||
- | And link it to your **/ | ||
- | <code bash> | ||
- | cd / | ||
- | ln -s / | ||
- | </ | ||
- | |||
- | the startup script | ||
- | |||
- | (note that the user services approach cannot be used because the //mount// command must be run as root) | ||
- | |||
- | === Protecting Apache behind the 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 - fileserver.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 | ||
- | } | ||
- | </ | ||
- | refer to the [[selfhost: | ||
- | |||
- | ===== NFS and SMB access ===== | ||
- | |||
- | This is the easiest part, you will simply use Gentoo' | ||
- | |||
- | So, emerge them and add the main services at boot: | ||
- | <code bash> | ||
- | emerge -v net-fs/ | ||
- | rc-update add default nfs | ||
- | rc-update add default samba | ||
- | </ | ||
- | |||
- | === NFS setup === | ||
- | Then setup the NFS share editing **/ | ||
- | <file - exports> | ||
- | / | ||
- | </ | ||
- | |||
- | And start the NFS service: | ||
- | < | ||
- | / | ||
- | </ | ||
- | |||
- | NFS export will probably mess a bit up on files ownership due to how Linux matches locla users with remote users, YMMV. | ||
- | |||
- | === Samba setup === | ||
- | |||
- | Edit the samba config file under **/ | ||
- | < | ||
- | ... omissis ... | ||
- | [global] | ||
- | | ||
- | | ||
- | | ||
- | hosts allow = 10.0.0. | ||
- | ... omissis ... | ||
- | [common] | ||
- | | ||
- | path = / | ||
- | valid users = <users list> | ||
- | | ||
- | guest ok = yes | ||
- | | ||
- | | ||
- | </ | ||
- | |||
- | Samba requires to specify a list of allowed users. | ||
- | |||
- | ===== Testing your FileServer ===== | ||
- | |||
- | To access via browser: | ||
- | |||
- | to access via WebDAV clients: **https:// | ||
- | |||
- | 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. | ||
- | |||
- | ===== Experimental stuff ===== | ||
- | |||
- | Just some additional experiments i did, for future references. | ||
- | |||
- | === Nephele-Serve === | ||
- | Replacing WebDAV with Nephele-Serve (which will support also CardDAV/ | ||
- | |||
- | https:// | ||
- | https:// | ||
- | |||
- | NPM needs to be enabled for the fileserver user: | ||
- | < | ||
- | NPM_PACKAGES=" | ||
- | mkdir -p " | ||
- | echo " | ||
- | </ | ||
- | |||
- | And in **~/ | ||
- | |||
- | < | ||
- | # NPM packages in homedir | ||
- | NPM_PACKAGES=" | ||
- | # Tell our environment about user-installed node tools | ||
- | PATH=" | ||
- | # Unset manpath so we can inherit from / | ||
- | unset MANPATH # delete if you already modified MANPATH elsewhere in your configuration | ||
- | MANPATH=" | ||
- | # Tell Node about these packages | ||
- | NODE_PATH=" | ||
- | </ | ||
- | |||
- | Install: | ||
- | <code bash> | ||
- | source ~/ | ||
- | npm install -g nephele-serve | ||
- | </ | ||
- | |||
- | Advantages: it's a simple server that supports pam_auth. In the future, it might **also** replace [[services: | ||
- | |||
- | Disadvantages: | ||
- | |||
- | === sFtpGO WebDAV / web browser === | ||
- | |||
- | Interesting [[https:// | ||
- | |||
- | You need to start it once then edit **sftpgo.json**: | ||
- | < | ||
- | " | ||
- | " | ||
- | " | ||
- | { | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | } | ||
- | ], | ||
- | </ | ||
- | Advnatages: easier than Apache to setup, support base_url | ||
- | |||
- | Disadvantages: | ||