transparently proxying a firewalled web application from a non-standard port to port 80

Posted by Terrence Brannon on Server Fault See other posts from Server Fault or by Terrence Brannon
Published on 2010-04-14T14:31:17Z Indexed on 2010/04/14 14:33 UTC
Read the original article Hit count: 391

Filed under:

I have a web application that serves on port 8088 on $server. However, the only port accessible from remote on $server is port 80. Furthermore, only CGI programs can execute on port 80.

I would like to write a CGI program accessible via port 80 that allows one to use the web app running on port 8088.

From my view, an ideal solution would be some sort of Java web browser that simply opened up a window and allowed me to use the program running on that port. The CGI program would simply initiate a web browser applet or something.

I wrote a Perl CGI program that does it, but I really would like a more transparent solution:

my $q = new CGI;

print $q->header;

use LWP::Simple;
use HTML::Tree;

my $base = "http://localhost:8088";

my $request = $base;

my $qurl = $q->param('url');

if (length($qurl) > 1) {

  warn "long $qurl";

  $request = "$base$qurl";

} else {
  warn "short $qurl";
}

my $content = get($request);
my $tree = HTML::TreeBuilder->new_from_content($content);
my @a = $tree->look_down('_tag' => 'a');

for my $a (@a) {
  my $url = $a->attr('href');
  next if index($url, '#') > -1 ;
  $url = "?url=$url";
  $a->attr(href => $url);
}

print $tree->as_HTML;

© Server Fault or respective owner

Related posts about reverse-proxy