Net-DNAT

 view release on metacpan or  search on metacpan

demo/suexec_mod_perl.pl  view on Meta::CPAN

    PerlModule Apache::DNAT
    PerlInitHandler Apache::DNAT
  </IfModule>
  [billy@localhost billy]$ httpd -f ~/conf/httpd.conf
  [billy@localhost billy]$

  (The same goes for the other users, too.)

  No <VirtualHost> sections should be used.  No special
  User directive or SuExec configuration is required.

=head1 ADMIN PROCEDURE

  As super user, turn on this DNAT server:

  [root@localhost /root]# suexec_mod_perl.pl --log_level=4

  And to turn it off:

  [root@localhost /root]# kill `cat /var/log/dnat/dnat.pid`


=head1 SEE ALSO

  apache, mod_perl, Net::DNAT, Apache::DNAT

=cut

use strict;
use Net::DNAT;

my $logdir = "/var/log/dnat";
my $nonroot = "nobody";

# Pools definition configuration
my $pools = {
  default => "127.0.0.1:8000",
  billy => "127.0.0.1:8001",
  henry => "127.0.0.1:8002",
  ralph => "127.0.0.1:8003",
};

# Default to some other service for all
# unknown or incomplete requests.
my $default_pool = "default";

my $host_dest = {
  "billy.com"      => "billy",
  "www.billy.com"  => "billy",
  "henry.com"      => "henry",
  "www.henry.com"  => "henry",
  "ralph.com"      => "ralph",
  "www.ralph.com"  => "ralph",
};

my ($uid,$gid) = (getpwnam $nonroot)[2,3];
if (!-d $logdir) {
  mkdir($logdir, 0755);
  if ($uid && $gid && # Taint cleaning
      "$uid:$gid" =~ /(\d+):(\d+)/) {
    chown($1, $2, $logdir);
  }
}

run Net::DNAT
  port => 80,
  pools => $pools,
  default_pool => $default_pool,
  host_switch_table => $host_dest,
  user => $uid,
  group => $gid,
  setsid => 1,
  log_file => "$logdir/error_log",
  pid_file => "$logdir/dnat.pid",
  ;



( run in 0.748 second using v1.01-cache-2.11-cpan-71847e10f99 )