15 Jul 2022
Using Aria2 with Ariang
Sahil Kokamkar![](https://sahil.twic.pics/image/blog/ariang-banner.jpg)
Table of content
Aria2
Aria2 is a lightweight cli download utility which supports multiple protocols such as HTTP/HTTPS, FTP, SFTP, BitTorrent and Metalink. It can also be controlled via JSON-RPC (which we are going to use with WSS) and XML-RPC.
Installing Aria2
Install aria2 using package manager. For e.g., in dnf:
sudo dnf install aria2 -y
Configuring Aria2
Once you have aria2 installed, create an aria2.conf
file in the /etc
directory. And paste the following settings:
# Change the Secret
rpc-secret=<YOUR_SECRET>
enable-rpc=true
# Only allow connection from nginx proxy
rpc-allow-origin-all=false
rpc-listen-all=false
max-concurrent-downloads=5
continue=true
max-connection-per-server=16
min-split-size=10M
split=10
max-overall-download-limit=0
max-download-limit=0
max-overall-upload-limit=0
max-upload-limit=0
# Download destination, should be the same in "/files" block of nginx config
dir=${HOME}/downloads
# Your session file location, and you shouldn't forget to create it before hand. (Or aria2c will fail to start.)
input-file=${HOME}/.aria2.session
save-session=${HOME}/.aria2.session
file-allocation=prealloc
referer=*
http-accept-gzip=true
save-session-interval=60
force-save=false
log-level=notice
# Log file
log=${HOME}/.aria2.log
allow-overwrite=true
# BT settings configure as you like
bt-tracker=
Create files for log and session
touch ${HOME}/.aria2.session ${HOME}/.aria2.log
Running the config
Run the following command in terminal
aria2c --conf-path=${HOME}/etc/aria2.conf -D
Note: The process will not restart if the server reboots, so create the following service file and enable it.
[Unit]
Description=Aria2c
After=network.target
[Service]
Type=simple
User=<your-username>
ExecStart=/usr/bin/aria2c --conf-path=/home/user/etc/aria2.conf
[Install]
WantedBy=multi-user.target
Installing AriaNg
First, make aria2
directory in /var/www/
using mkdir aria2
and cd
to it.
Then download and unzip it using by running the following command:
wget https://github.com/mayswind/AriaNg/releases/download/1.2.4/AriaNg-1.2.4-AllInOne.zip && 7z -e A*
Setting up Nginx
Create a ariang.conf
file in /etc/nginx/sites-available/
and paste the following config:
server {
listen 80;
listen [::]:80;
root /var/www/aria2; #AriaNg Location
index index.html;
server_name <your-domain>;
access_log /var/log/nginx/ariang.access.log;
error_log /var/log/nginx/ariang.error.log;
location / {
try_files $uri $uri/ =404;
}
location /jsonrpc {
proxy_pass http://localhost:6800/jsonrpc;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /files {
auth_basic "Restricted Content";
auth_basic_user_file /etc/nginx/.htpasswd;
alias /home/USER/downloads;
autoindex on;
}
}
After that save and create a symbolic link to it using:
sudo ln -s /etc/nginx/sites-available/ariang.conf /etc/nginx/sites-enabled/
To protect your download directory using password, run sudo htpasswd -c /etc/nginx/.htpasswd <username>
and entry your password.
Then finally test your nginx config using sudo nginx -t
and reload the server sudo nginx -s reload
.
And make sure to configure your DNS record and install SSL certificate using these steps.
Configuring AriaNg
Once you're done setting up nginx. Go to <your-domain>/#!/settings/ariang
and go to RPC tab and change Aria2 RPC Protocol
to WebSocket Security(WSS) and the port to 443
.
Add your rpc-secret in Aria2 RPC Secret Token
and hit Activate and reload the page.
Now you should be able to see the Aria2 status as connected
Congrats🎉, you have successfully configured Aria2Ng.