1

I have 2 computers behind a router, and a raspberry pi. I have port forwarded port 80 to the public IP, and I want to do the following.

I will describe the end result I'm trying to achieve:

I want traffic sent to

http://public_ip/a/randomurlstring

To be received at

http://192.168.1.12/randomurlstring

And all traffic sent to

http://public_ip/b/randomurlstring

To be received at

http://192.168.1.13/randomurlstring

Currently, I'm running an apache web server with some rewrite rules and a glype proxy to load the local IPs via the Pi, but I am wondering if there is a better way to do it.

1
  • This is a networking or web servers question, not specific to the raspberry pi. Oct 20, 2013 at 14:00

2 Answers 2

2

You could probably do this with a load balancer. I wrote an article about setting one up here: http://raspberrywebserver.com/raspberrypicluster/raspberry-pi-cluster.html.

In /etc/apache2/sites-available/default, I set up one cluster with several IP addresses. You would need to set up two clusters, one for IP address 192.168.1.12 and another cluster for 192.168.1.13. (It's not a problem if there's only one node in each cluster).

Then in the same file, you need to add some lines of code to pass traffic to each cluster. Something like this:

ProxyPass http://public_ip/a/* balancer://clustera/
ProxyPass http://public_ip/b/* balancer://clusterb/
2

You can do this with Apache Rewrite Module. By default Apache comes with rewrite module installed, if don't please do this.

sudo echo "LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so" > /etc/apache2/mods-available/rewrite.load
sudo a2enmod rewrite  
sudo /etc/init.d/apache2 reload

Then you should create a .htaccess file in your web folder (default /var/www/ for debian systems). Add this line into .htaccess file:

RedirectMatch 301 ^/a/(.*)$ http://192.168.1.12/$  
RedirectMatch 301 ^/b/(.*)$ http://192.168.1.13/$

If you forward port 80 to server which running apache everything should work fine.

1
  • I want it accessible from all IPs, not just local ones. Sep 14, 2013 at 12:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.