💾 Archived View for her.st › blog › simplifying-our-image-hosting-service.gmi captured on 2023-11-14 at 08:01:31. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-01-29)
-=-=-=-=-=-=-
Last time we've setup vsftp to handle our image uploads. This foolishness ends now. We've already got our SSH Server up and we can easily transfer files through it.
Let's do that, shall we?
apt remove vsftp -y
Apache configs suck.
Hello nginx.
apt remove apache2 -y && apt install nginx -y
Let's also change the domain from *h.img.alumni.re* to *cdn.her.st* as I'm not going to be using my homeserver anymore.
We're going to use *threaded async IO* and *sendfile* for maximum throughput on potentially big files like binary data, audio and video but not for small things like images and assets (which are mostly css and js text files). There's some added latency involved when using threaded async IO so its only worth paying that overhead if the file tansfer will usually take more than a couple seconds. We really don't want to add any additional latency to image requests as that would unnecessarily slow down page loading speed.
server { listen 80; root /srv/http/cdn.her.st; index index.html; server_name cdn.her.st; location / { try_files $uri $uri/ =404; } location /bin { sendfile on; aio threads; try_files $uri $uri/ =404; } location /videos { sendfile on; aio threads; try_files $uri $uri/ =404; } location /audio { sendfile on; aio threads; try_files $uri $uri/ =404; } location /assets { sendfile on; try_files $uri $uri/ =404; } }
Now let's spin up the service and we're done!
systemctl enable nginx --now
#!/bin/bash path=$1 filename=$2 if [ -z $filename ]; then filename=$(basename $path) fi scp -q $path trbl@cdn.her.st:/srv/http/cdn.her.st/images/$filename echo "/assets/images/$filename" | xclip -sel clip echo "/assets/images/$filename (added to clipboard)"
usage:
imgup /path/to/image.jpg [Optional remote filename]
Much better than the C# clusterfuck with multiple classes.
The first iteration brought down complexity and increased performance! Can't ask for a better outcome considering how little effort this took.