Setting up an Aria2 Server with WebUI

Introduction

This is a tutorial on how to set up an Aria2 multi-purpose download client as a server on your Raspberry Pi, which is managable over a UI in your browser. A Debian based OS with systemd is expected.

Environment

Hardware

Raspberry Pi 3 Model B

OS

DietPi v6.25.3

Step by Step Instructions

1. Installation of Dependencies

sudo apt update
sudo apt install -y curl
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt update
sudo apt install -y build-essential nodejs git nginx aria2 openssl

 2. Create System-User aria

useradd --system --create-home --shell /bin/bash --password <your-password-here> aria

3. Create needed folders and files

cd /home/aria
mkdir dl
touch aria.conf
sudo openssl rand -base64 32 > token.txt

4. Configure Aria2

Paste the following code block into the previously created aria.conf.
Replace the value of rpc-secret with the output of cat /home/aria/token.txt.

##files
dir=/home/aria/dl
file-allocation=none # Allocation was too slow in my case; you can try `falloc` or `trunc`
continue=true
daemon=true
disk-cache=32M

##logging
log=/home/aria/aria2.log
console-log-level=warn
log-level=notice

##downloads
max-overall-download-limit=5M
max-concurrent-downloads=15
max-connection-per-server=5
min-split-size=20M
split=4
disable-ipv6=true

##sessions
force-save=true
input-file=/home/aria/aria2.session
save-session=/home/aria/aria2.session
save-session-interval=10

##security
http-auth-challenge=true
check-certificate=false
enable-rpc=true
rpc-listen-all=true
rpc-secret=<your-token-here>

#rpc-secure=true	
#rpc-allow-origin-all=true
#rpc-certificate=/home/aria/aria2.pfx

##ports
rpc-listen-port=6800

##others
summary-interval=120
enable-dht=true

##times
timeout=600
retry-wait=30
max-tries=50

5. Create an Aria2 systemd Service

Create the file /lib/systemd/system/aria2.service with the following content:

[Unit]
Description=Aria2 download manager
Requires=network.target
After=dhcpcd.service
    
[Service]
Type=forking
User=aria
RemainAfterExit=yes
ExecStart=/usr/bin/aria2c --conf-path=/home/aria/aria.conf
ExecReload=/usr/bin/kill -HUP $MAINPID
ExecStop=/usr/bin/kill -s STOP $MAINPID
RestartSec=1min
Restart=on-failure
    
[Install]
WantedBy=multi-user.target

6. Start the systemd Service

systemctl start aria2

7. Installing the WebUI

su - aria
cd ~
git clone https://github.com/ziahamza/webui-aria2
cd webui-aria2
cp docs/* /var/www/html/

8. Accessing the WebUI over Nginx

Find out the local IP of your Raspberry Pi. Then access the WebUI in your browser by visiting the local IP. Go to Connection Settings and enter the output of cat /home/aria/token.txt. Then Save.

If the WebUI sucessfully connected to the Aria2 RPC Server now, then everything is configured correctly.

Optionally, you may delete /home/aria/token.txt now, as it contains the RPC secret.

Sources