NGINX PHP FPM RTORRENT - Novik/ruTorrent GitHub Wiki

Prerequisites

The following group should be created: rtorrent-socket
We assume that rtorrent is running under rtorrent user.
NGINX worker is running under www-data user.
PHP-FPM worker(s) is running under rutorrent user.
All three users belong to rtorrent-socket group.

RTorrent configuration

In .rtorrent.rc file the following lines should be added

execute.nothrow = rm,~/.rtorrent.sock
network.scgi.open_local = /home/rtorrent/.rtorrent.sock
schedule = socket_chmod,0,0,"execute=chmod,0660,~/.rtorrent.sock"
schedule = socket_chgrp,0,0,"execute=chgrp,rtorrent-socket,~/.rtorrent.sock"

PHP-FPM configuration

We assume that in /etc/php5/fpm/php.ini you have the following setting:

cgi.fix_pathinfo=1

In that case you can have the following configuration inside /etc/php5/fpm/pool.d/rutorrent.conf

[rutorrent]
user = rutorrent
group = rutorrent
listen = /var/run/php-fpm-rutorrent.sock
listen.owner = rutorrent
listen.group = www-data
listen.mode = 0660
pm = static
pm.max_children = 2
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
chdir = /

NGINX configuration

Inside your http section of nginx.conf you should include the following lines:

upstream backendrutorrent {
        server unix:/var/run/php-fpm-rutorrent.sock;
}
upstream backendrtorrent {
        server unix:/home/rtorrent/.rtorrent.sock;
}

And inside server section include the lines below:

location /rutorrent {
    access_log /var/log/nginx/rutorrent.access.log;
    error_log /var/log/nginx/rutorrent.error.log;
    location ~ .php$ {
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_pass    backendrutorrent;
        fastcgi_index   index.php;
        fastcgi_param   SCRIPT_FILENAME $document_root/rutorrent$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_intercept_errors        on;
        fastcgi_ignore_client_abort     off;
        fastcgi_connect_timeout         60;
        fastcgi_send_timeout            180;
        fastcgi_read_timeout            180;
        fastcgi_buffer_size             128k;
        fastcgi_buffers                 4       256k;
        fastcgi_busy_buffers_size       256k;
        fastcgi_temp_file_write_size    256k;
    }
}

location /RPC2 {
    access_log /var/log/nginx/rutorrent.rpc2.access.log;
    error_log /var/log/nginx/rutorrent.rpc2.error.log;
    include /etc/nginx/scgi_params;
    scgi_pass backendrtorrent;
}