DIY Nginx + ruTorrent Seedbox on Wheezy (Part 1)
Get some coffee/tea/coke/drink of choice and some snacks. This’ll take a while. We’ll be taking a barebone stock Debian system and set up a killer seedbox all from scratch, using rTorrent/libTorrent, ruTorrent and Nginx with SSL.
Install Nginx and PHP
Most of the guides you’ll find on ruTorrent use Apache as the server, because - well, Apache. We’ll be using Nginx instead, because - well, Nginx. So we need to install it.
1 | apt-get install nginx php5-fpm
|
I like to keep my my server files in /var/www
. So we need to tell PHP where it’s at. Open /etc/php5/fpm/php.ini
and change open_basedir
to /var/www
.
Create User
We need a user to run rTorrent. You can name it whatever you want, but if you chose something different, remember to adjust the configs in the rest of this article.
We’ll also be creating a common group for this user and Nginx.
1 2 3 | groupadd rutorrent
useradd -G rutorrent user
usermod -a -G rutorrent www-data
|
Setting up SSL
Security doesn’t hurt, so while we’re at it, we might as well set up SSL for Nginx. This is for personal use (you don’t really plan to share your Seedbox with others, do you?), so a self-signed cert should be good enough for now. If you feel like you want to get it signed somewhere else, go ahead and send me you money instead.
1 2 3 4 5 6 7 | mkdir -p /etc/nginx/ssl
cd /etc/nginx/ssl
openssl genrsa -des3 -out server.key 2048
openssl req -new -key server.key -out server.csr
mv server.key server.key.orig
openssl rsa -in server.key.orig -out server.key
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
|
Working Dir
I’ll try to keep things clean, that’s why I’m creating a temporary directory to work in.
1 | mkdir ~/workdir; cd ~/workdir
|
Install XMLRPC-C
rTorrent and Nginx need this to be able to communicate with each other.
1 2 3 4 | svn checkout http://svn.code.sf.net/p/xmlrpc-c/code/advanced xmlrpc-c
cd xmlrpc-c
./configure --disable-cplusplus
make; make install
|
Install libTorrent
Clone and compile, nothing special.
1 2 3 4 5 6 | cd ~/workdir
git clone https://github.com/rakshasa/libtorrent.git
cd libtorrent
./autogen.sh
./configure
make; make install
|
Install rTorrent
Again - clone and compile. We need to make sure we configure --with-xmlrpc-c
.
1 2 3 4 5 6 7 | cd ~/workdir
git cone https://github.com/rakshasa/rtorrent.git
cd rtorrent
./autogen.sh
./configure --with-xmlrpc-c
make; make install
ldconfig
|
Install and configure ruTorrent
This one is rather easy. We just need to clone the git repo into /var/www
1 2 | mkdir -p /var/www; cd /var/www
git clone https://github.com/Novik/ruTorrent.git
|
ruTorrent doesn’t need a lot of configuration. Let’s take a look at /var/www/ruTorrent/conf/config.php
.
1 2 3 | $topDirectory = "/home/user"
$scgi_port = 0;
$scgi_host = "unix:///home/user/.rtorrent-scgi.sock"
|
Set up a Server Block
Nginx has “Server Blocks” for the individual apps running on the server. Let’s create one for ruTorrent.
/etc/nginx/sites-available/rutorrent
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | server {
listen 443 ssl;
server_name yavin.trashbukk.it trashbukk.it localhost;
root /var/www/ruTorrent;
index index.html index.htm index.php;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
location / {
try_files $uri $uri/ =404;
}
location /RPC2 {
include scgi_params;
scgi_pass unix:/home/user/.rtorrent-scgi.sock;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
|
We also want it password-protected. We wouldn’t want the world to see all your pr0n.
1 2 | apt-get install apache2-utils
htpasswd -c /etc/nginx/.htpasswd user
|
Aaand reload
1 | service nginx reload
|
Install some needed packages for ruTorrent plugins
Some of ruTorrent’s plugins need some additional binaries. This seems like a good time to install them.
1 | apt-get install php5-cli ffmpeg mediainfo
|
Get rtorrent to start at boot
Nginx runs on boot by default, so no issue there. But we want rtorrent to start, too. We’re lazy like that.
Many people will tell you to write an init script for this, but IMO that’s overkill. I prefer to use /etc/rc.local
1 | start-stop-daemon --start --chuid seed --name rtorrent --exec /usr/bin/screen -- -fa -d -m /usr/local/bin/rtorrent
|
That’s it!
Try it, reboot your server and see everything running!