Page 1 of 5

Howto: Proxying deluge web client to Apache via mod_proxy

Posted: Sun Sep 28, 2008 3:16 pm
by oxyis
Deluges web client is the only client I use, but I wanted to access it via my own web server. This small Howto shows how I got it to work. This has only been tested with Apache 2.2 and Deluge 1.0.0.

Network setup

The idea is to use Apache and mod_proxy to redirect all communication on the web server to the deluge web client running on my file server. Deluge can either be on the same server or on a different server.

[*] IP; 10.0.0.3 - Internal file server with deluge web client,
[*] IP; 10.0.0.2 - Web server with Apache 2.2

The following apache modules are needed;

[*] mod_proxy
[*] mod_proxy_html


Configuration of Apache

The code below will proxy all request on http://example.org/deluge/ and http://example.org/torrent/ to http://10.0.0.3:8112/. Then when the HTML code are sent back and forth to the web browser, the HTML links will be rewritten to work on the deluge web client.

Code: Select all

        ProxyRequests off
        ProxyPass /deluge/ http://10.0.0.3:8112/
        ProxyPass /torrent/ http://10.0.0.3:8112/torrent/
        ProxyHTMLURLMap http://10.0.0.3:8112 /deluge

        <Location /deluge/>
                ProxyPassReverse /
                SetOutputFilter  proxy-html
                ProxyHTMLURLMap  /      /deluge/
                ProxyHTMLURLMap  /deluge  /deluge
                RequestHeader    unset  Accept-Encoding
        </Location>

        <Location /torrent/>
                ProxyPassReverse /
                SetOutputFilter  proxy-html
                ProxyHTMLURLMap  /      /deluge/
                RequestHeader    unset  Accept-Encoding
        </Location>
The configuration setup is based on this guide;
http://www.askapache.com/htaccess/rever ... pache.html

Remember to secure your /deluge/ and /torrent/ locations via authentication or other means.

Re: Howto: Proxying deluge web client to Apache via mod_proxy

Posted: Tue Oct 21, 2008 12:14 am
by orbisvicis
Well, this should work on embedded css/javascript links as well. Also the actual list of required modules

Required Apache 2.x modules
[*] mod_proxy
[*] mod_proxy_http
[*] mod_proxy_html
[*] mod_headers

Code: Select all

ProxyRequests off
ProxyHTMLExtended on
ProxyPass /deluge/ http://127.0.0.1:8112/
ProxyHTMLURLMap http://127.0.0.1:8112 /deluge

<Location /deluge/>
        ProxyPassReverse /
        SetOutputFilter proxy-html
        ProxyHTMLURLMap / /deluge/ ec
        ProxyHTMLURLMap /deluge /deluge ec
        ProxyHTMLURLMap ([^*])(\/[^*].*) $1/deluge$2 hRxL
        RequestHeader unset Accept-Encoding
        Order allow,deny
        Allow from all
</Location>
see http://apache.webthing.com/mod_proxy_html/ for more information

Re: Howto: Proxying deluge web client to Apache via mod_proxy

Posted: Wed Oct 22, 2008 1:45 am
by orbisvicis
Here's the version that works with the external javascripts as well ... if I missed a few urls just add them in. Also, replace the placeholders with information relevant to your webserver.

Additional Required Apache 2.x modules
[*] mod_rewrite

Code: Select all

ProxyRequests off
ProxyHTMLExtended on
ProxyPass /deluge/ http://127.0.0.1:8112/
ProxyHTMLURLMap http://127.0.0.1:8112 /deluge

RewriteEngine on
RewriteCond %{HTTP_REFERER} MyProtocol://MyWebsite:MyPort/deluge/index
RewriteCond %{REQUEST_URI} ^/torrent/info_inner/.*
RewriteCond %{REQUEST_URI} !^/deluge/.*
RewriteRule ^/(.*) /deluge/$1 [PT]

<Location /deluge/>
        ProxyPassReverse /
        SetOutputFilter proxy-html
        ProxyHTMLURLMap / /deluge/ ec
        ProxyHTMLURLMap /deluge /deluge ec
        ProxyHTMLURLMap ([^*])(\/[^*].*) $1/deluge$2 hRxL
        RequestHeader unset Accept-Encoding
        Order allow,deny
        Allow from all
</Location>
Its an **enormous** hack for a simple thing, but necessary since mod_proxy_html only parses documents of text/html content-type headers for urls. Alternatively you could rewrite the two links in deluge.js usually located at

Code: Select all

/usr/lib/python2.5/site-packages/deluge-1.1.0_dev-py2.5-linux-i686.egg/deluge/ui/webui/static
Obviously mod_rewrite could be used entirely in lieu of mod_proxy_html, but then the /torrent and the /index locations become dedicated to deluge and thats undesirable. This setup checks the referer_header to make sure the request comes from the proxy <location> directive, so you dont even lose the /torrent location. yay!

Lastly some of the html is badly formed and wont be parsed by mod_proxy_html, so in case it hasnt been fixed yet, change all the <image tags to <img tags at

Code: Select all

classic/part_button.html
white/part_tb_button.html

Re: Howto: Proxying deluge web client to Apache via mod_proxy

Posted: Thu Oct 23, 2008 6:23 pm
by mvoncken
I want to make proxying easyer, but I'm missing some mod-proxy knowledge.

Latest svn (r4087) contains an experimental command-line parameter

The 1st argument after deluge -u web is interpreted as the base-url.
This will prefix all url's and redirects with that base url:
For example :

Code: Select all

deluge -u web /deluge
Apache modules

Code: Select all

sudo a2enmod headers
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_connect
/etc/apache2/apache2.conf
(edit:r4088 : redirects according to http spec/fixed ProxyPassReverse)

Code: Select all

ProxyRequests off
ProxyPass /deluge/ http://127.0.0.1:8112/

<Location /deluge/>
	ProxyPassReverse http://127.0.0.1:8112/deluge/
	Order allow,deny
	Allow from all
</Location>
Any other suggestions on how to improve proxying are welcome.
please test this!

Re: Howto: Proxying deluge web client to Apache via mod_proxy

Posted: Sat Nov 22, 2008 11:04 am
by lenwar
(using latest SVN 4247)
Works like a charm except for the status icons... They lack the /deluge/-part in the URL's and give broken image-links.
https://<domain>/pixmaps/all rather than https://<domain>/deluge/pixmaps/all

Re: Howto: Proxying deluge web client to Apache via mod_proxy

Posted: Sat Nov 22, 2008 1:07 pm
by mvoncken
lenwar wrote:(using latest SVN 4247)
Works like a charm except for the status icons... They lack the /deluge/-part in the URL's and give broken image-links.
https://<domain>/pixmaps/all rather than https://<domain>/deluge/pixmaps/all
Thanks for the report, i'll fix that.

Re: Howto: Proxying deluge web client to Apache via mod_proxy

Posted: Sat Dec 06, 2008 1:47 am
by jbonevia
mvoncken wrote:I want to make proxying easyer, but I'm missing some mod-proxy knowledge.

Latest svn (r4087) contains an experimental command-line parameter

The 1st argument after deluge -u web is interpreted as the base-url.
This will prefix all url's and redirects with that base url:
For example :
deluge -u web /deluge
Hi, i have tried this with deluge 1.06 running on my web server and was unable to get it working, i think that when i start up deluge with 'deluge -u web /deluge' and navigate to my web server 'http://172.16.1.1/deluge' it is not appending the /deluge/ to the URL. I'm not sure if i am doing something wrong or not.

I went back to the solution posted by orbisvicis and this works well except for the individual torrent stats that show at the bottom of the page, here i just get an error displaying in the browser:

Not Found
The requested URL /torrent/info_inner/a92r432g5vcd49ggf1dc30455321afdcfa5cd876 was not found on this server.

I'll keep plugging away to see if i can fix it or work out where i went wrong.

Re: Howto: Proxying deluge web client to Apache via mod_proxy

Posted: Sat Dec 06, 2008 3:11 am
by jbonevia
jbonevia wrote: I went back to the solution posted by orbisvicis and this works well except for the individual torrent stats that show at the bottom of the page, here i just get an error displaying in the browser:

Not Found
The requested URL /torrent/info_inner/a92r432g5vcd49ggf1dc30455321afdcfa5cd876 was not found on this server.

I'll keep plugging away to see if i can fix it or work out where i went wrong.
Think i know what is causing this - i've got some funny stuff going on with virtual hosts for Joomla running on the same box, it's affecting the path in the Rewrites, it might be affecting the 'deluge -u web /deluge' method too :oops:

Re: Howto: Proxying deluge web client to Apache via mod_proxy

Posted: Sat Dec 06, 2008 9:32 am
by phantom
I would like to run WebUi over https. Will this proxying method work for that, or am I required to always run WebUI over http?

Re: Howto: Proxying deluge web client to Apache via mod_proxy

Posted: Sat Dec 06, 2008 6:08 pm
by lenwar
Yes, you can use https to your apache-server and use the mod_proxy module locally on the same box with http.

web --https--> apache --http--> deluge-web-ui