Jump to content

Virtual Hosts using Apache and proxy rewrite to uTorrent's port


AgentWolf

Recommended Posts

Posted

I wanted to configure my Apache Web Server, to have Virtual Hosts, so I can host my Web Site on www.mydomain.com and the Web UI of uTorrent on utorrent.mydomain.com.

Both of them are running on port 80 so I can access them from my job, where we have a very restricted firewall that allows only connections on port 80.

Here are the steps:

1. Enable Web UI on uTorrent (Let's say that it listens on port 6881)

2. Configure apache conf files as follows:

<VirtualHost *:80>
ServerAdmin admin@mydomain.com
DocumentRoot C:/htdocs #Here are my Web Site files
ServerName www.mydomain.com
ErrorLog logs/www.mydomain.com-error_log.log
CustomLog logs/www.mydomain.com-access_log.log common
</VirtualHost>

<VirtualHost *:80>
ServerName utorrent.mydomain.com
RewriteEngine on
RewriteRule ^/gui/(.*)$ http://127.0.0.1:6881/gui/$1 [P,L]
RewriteRule ^/(.*)$ http://127.0.0.1:6881/gui/$1 [P,L]
ErrorLog logs/utorrent.mydomain.com-error_log.log
CustomLog logs/utorrent.mydomain.com-access_log.log common
</VirtualHost>

3. Start (or Restart) Apache and you are done.

The result is that Apache is listening on port 80 for http requests.

Every request which is made to www.mydomain.com lands to my Web Site (In the address bar you see something like that: http://www.mydomain.com/index.html)

Every request which is made to utorrent.mydomain.com for forwarded to uTorrent's Web UI (In the address bar you see this: http://utorrent.mydomain.com/). No '/gui/' is needed.

Posted

Nice!

It is only slightly more complicated the the ReverseProxy but you don't have to use gui anymore if you don't want to.

Please note that you also have to add/uncomment the LoadModule rewrite_module modules/mod_rewrite.so line in the main Apache config file.

Also note that to access multiple instances of µtorrent you'll have to use multiple subdomains. (utor1.mydomain.com, utor2.mydomain.com, etc) and make VirtualHosts for each.

  • 1 month later...
Posted

Sorry for the bump, but I'm really interested in getting this done.

I configured the VirtualHosts thing as you posted above (obviously with changed domain and port), in .../etc/extra/httpd-vhosts.conf , and then on the .../etc/httpd.conf file I uncommented the line "include /extra/httpd-vhosts.conf, but when I try to restart apache it won't start up... I have also tried adding the code to the main httpd.conf file but neither work, it just tells me that apache can't start up, it doesn't seem to like the code? Or have I done something wrong (more likely)?

Posted

Can you please post the error message from the error log of apache?

The error log file, is defined on the Virtual Host configuration, and it's the "ErrorLog" option.

  • 6 months later...
Posted

<VirtualHost *:80>
ServerName localhost/test1
RewriteEngine on
RewriteRule ^/gui/(.*)$ http://127.0.0.1:6881/gui/$1 [P,L]
RewriteRule ^/test1/(.*)$ http://127.0.0.1:6881/gui/$1 [P,L]
</VirtualHost>

<VirtualHost *:80>
ServerName localhost/test2
RewriteEngine on
RewriteRule ^/gui/(.*)$ http://127.0.0.1:6882/gui/$1 [P,L]
RewriteRule ^/test2/(.*)$ http://127.0.0.1:6882/gui/$1 [P,L]
</VirtualHost>

First virtual is working fine, however whenever i access second, its return error 404.

What should i change to make it work both?

Posted

I think you don't understand what a virtualhost is.

No matter, basically it boils down to these two issues:

A) you can't use / in a virtualhost name.

B) you need actual domain names

This means that with the localhost domain there is no way to make two virtualhosts.

The simplest way to get what you want is to first make two rewrite rules on a single virtualhost:

<VirtualHost *:80>
ServerName localhost
RewriteEngine on
RewriteRule ^/test1/(.*)$ http://127.0.0.1:6881/gui/$1 [P,L]
RewriteRule ^/test2/(.*)$ http://127.0.0.1:6882/gui/$1 [P,L]
</VirtualHost>

And then edit the webui.js which can be found in the webui.js.gz file in the webui.zip with a text editor and replace the 4 occurrences of /gui/ with /test1/ (for the webui.zip of the µtorrent running on port 6881) and /test2/ (for the one on 6882) accordingly.

There is a (arguably) more difficult way. You could install the Webui Shell and make two instances in it and then a user for each instance. Then you'd be able to access both µtorrent instances on /gui/.

Posted

I'm having a few problems with this. I've setup the virtual hosts, but when I go to seedbox.domain.com (no, it's not domain.com, ive blanked it out) it comes up with a 403 Forbidden error. When I add :port/gui to the domain, the login box comes up and it works. What am I doing wrong?

EDIT: Don't worry, all sorted out. FYI, I had to enable the proxy.load and proxy_http.load mods in Apache, and it started working straight away after a restart. Thanks for the instructions op!

  • 1 month later...
  • 8 months later...
Posted

I found a way to add Iphone webui support. You can have apache automatically rewrite to the iphone webui if you are using an iphone and still have the rewrite rules work properly for other browsers.

<VirtualHost *:80>
ServerAdmin admin@mydomain.com
DocumentRoot C:/htdocs #Here are my Web Site files
ServerName www.mydomain.com]
ErrorLog logs/www.mydomain.com-error_log.log
CustomLog logs/www.mydomain.com-access_log.log common
</VirtualHost>

<VirtualHost *:80>
ServerName utorrent.mydomain.com
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} .*Mobile.*Safari
RewriteRule ^/gui/iphone/(.*)$ http://127.0.0.1:6881/gui/iphone/$1 [P,L]
RewriteCond %{HTTP_USER_AGENT} .*Mobile.*Safari
RewriteRule ^/gui/(.*)$ http://127.0.0.1:6881/gui/$1 [P,L]
RewriteCond %{HTTP_USER_AGENT} .*Mobile.*Safari
RewriteRule ^/$ http://127.0.0.1:6881/gui/iphone/i.html [P,L]
RewriteCond %{HTTP_USER_AGENT} .*Mobile.*Safari
RewriteRule ^/(.*)$ http://127.0.0.1:6881/gui/iphone/$1 [P,L]

RewriteRule ^/gui/(.*)$ http://127.0.0.1:6881/gui/$1 [P,L]
RewriteRule ^/(.*)$ http://127.0.0.1:6881/gui/$1 [P,L]
ErrorLog logs/utorrent.mydomain.com-error_log.log
CustomLog logs/utorrent.mydomain.com-access_log.log common
</VirtualHost>

I know, it looks pretty messy, but I can verify that it works. This only works properly if you have the "iphone" folder in webui.zip and if the iphone webui is originally at "ip:port/gui/iphone/i.html". This will also work with the ipad webui, you'll just have to change up the rewrite rules.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...