Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

502 Bad Gateway Error with ModPerl scripts

by thunders (Priest)
on Sep 29, 2003 at 14:42 UTC ( #294972=perlquestion: print w/replies, xml ) Need Help??
thunders has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to get a mod_perl enabled server running from my home PC. The way it's set up currently I have a server on port 80 for static requests, and another on port 8200 for mod_perl.

I have apache set up to send requests to the http://myhost/perl/ subdirectory to my mod_perl server, with this rewrite rule:

<IfDefine PERLPROXIED> <IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^proxy:.* - [F] RewriteRule ^(.*\/perl\/.*)$ http://%{HTTP_HOST}:8200$1 [P] RewriteRule ^(.*\/cgi-perl\/.*)$ http://%{HTTP_HOST}:8200$1 [P] </IfModule> </IfDefine>

This works when I connect from a computer on my home network, but If I try to call the scripts from the internet. I get a "502 Bad Gateway" Error. I assume it is because the %{HTTP_HOST} variable is filled in with a router assigned internal IP.

I think I need to set up a different rewrite rule for external requests. Does anyone know how to do that?

Replies are listed 'Best First'.
Re: 502 Bad Gateway Error with ModPerl scripts
by zby (Vicar) on Sep 29, 2003 at 15:10 UTC
    How about not using the %{HTTP_HOST} variable but hardcoding the address? This of course would apply only if you have just one address but for a home PC I would expect that.
      That's my plan for external requests, but then it wouldn't work right for internal stuff. I'm not sure if I can tell apache to use a different rule for requests coming from 192.168.0.* I'm sure there's a way.

        If you're proxying requests, your Web server will be making the connection, so the hostname needs to be something your Web server can connect to. It could be as simple as hardcoding in

        My suspicion is that when you're browsing internally, you're doing something like, so when Apache rewrites the address to proxy, it connects to When you're coming from the outside, you're visiting Apache rewrites the address, tries to connect to, gets the IP address of the public side of the NAT, and can't connect to it. If that's the case, another solution is split horizon DNS, so that inside your network resolves to, while outside it resolves to your external NAT address.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://294972]
Approved by jdtoronto
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2017-09-21 09:31 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (244 votes). Check out past polls.