Simple NGINX File Server and How to Share Files With Your Friends

Edit: I’m moving away from doing this, it just doesn’t work that well and rclone has some issues with transferring files. I’ll leave the post up anyway.

I’m moving away from MEGA for a number of reasons. One of them is that they have started nuking accounts for having DMCA-able content. The mechanism of how this works is thought to be:

So, re-uploading content is a safe way to make your files unique from MEGA’s perspective. The problem exists with importing files from other accounts.

There are some alternatives to MEGA. Unfortunately none of them do everything MEGA does:

Nextcloud is stuck with an inefficient PHP codebase, Owncloud has a bunch of different products that do not seem geared to people outside of the sysadmin sphere, etc etc…

I tried Syncthing as it’s a promising alternative, but it does not support sharing files outside of the Syncthing network and there are some other issues I ran into, such as adding the APT repo. I’m probably stupid, but no matter what I did apt would not take the PGP key. This is an issue because my VPS runs Debian (focused on stable software) and my laptop runs KDE Neon (cutting edge developer distro) so there was a serious version mismatch: 1.12 to 1.18. 1.12 seems to lack support for untrusted devices so I was not able to encrypt my personal files. Unless I figure out the APT thing, this is a no go!

I already pay a couple dollars for a VPS and I already have rights to a domain name and I can easily and affordably add storage to my VPS, so why not take advantage of that?

So, the simplest option I thought of was to use NGINX indexing functionality to serve files. This isn’t a new idea, but paired with rclone it should be a very functional way to share files and folders with people.

To begin, you should read this article about setting it up. Rclone is really cool because it can work off existing protocols like SSH/SFTP. This is what we’re going to use to send files to our GNU/Linux VPS. Here’s my config in ~/.config/rclone/rclone.conf for you to cross-reference:

[myvps]
type = sftp
host = wojak.cafe
user = root
key_file = ~/.ssh/id_rsa
known_hosts_file = ~/.ssh/known_hosts
md5sum_command = md5sum
sha1sum_command = sha1sum

[myvps_crypt]
type = crypt
remote = myvps:crypted
filename_encryption = obfuscate
directory_name_encryption = true
password = CENSORED

You can then sync files straight to the server. However, we probably don’t want them inside /var/www/wojakcafe as it would be a messy place to put them on top of the directory being root only. Instead, we should create a new user with limited permissions, copy the files there and then NGINX will have no problem indexing them. (If you didn’t do this, you would have to set /root as 700 instead of 755 permissions or mount a folder into that location, which we can avoid)

useradd -m grayson
passwd grayson

This creates a new user named “grayson” and a home directory for him (-m) and passwd prompts you to set a password for the user.

Now we can create a symlink inside /var/www to the home directory or a folder inside of it:

ln -s /home/grayson /var/www/wojakcafe/shared

This creates a symbolic link enabling NGINX to share files not inside the website directory.

You may need to explicity enable indexing in our website config file, located at /etc/nginx/sites-enabled/wojakcafe by adding the “autoindex on;” in the server block:

server {
        autoindex on; 
        server_name wojak.cafe ;
        root /var/www/wojakcafe ;
        index index.html index.htm index.nginx-debian.html ;
        location / {
                try_files $uri $uri/ =404 ;
        }

Finally, we rclone:

rclone -vv copy Switch/ myvps:/home/grayson

If we wanted the files to tranfer encrypted (not useful in this scenario) we would simply specify the crypt instead:

rclone -vv copy Switch/ myvps_crypt:/home/grayson

To see the remotes you’ve configured in rclone, either view your config or run

rclone listremotes

FIN

Previous:
Intro to Hydroponics - Aeroponics BOM
Next:
Password Syncing Between your non-Safari Desktop Browser and iPhone
Related
Computers