[prev in list] [next in list] [prev in thread] [next in thread] 

List:       apache-modperl
Subject:    RE: Proxying -- Loss of Environment Vars?
From:       Ken Williams <ken () forum ! swarthmore ! edu>
Date:       1999-02-28 20:51:56
[Download RAW message or body]

rweiss@inforelay.com (Russell D. Weiss) wrote:

>Ken,
>
>So basically, when the proxying Apache connects to the port of the back-end
>Apache, it will send something similar to this:
>
>GET / HTTP/1.0
>X-Forwarded-For: 123.456.789.0
>\n
>\n

That's right.


>
>Is that what is happening?  I added the includes to the mod_proxy.c and
>added the code at the bottom.  I figured this would be a safe way to go
>since mod_proxy.c would be compiled in.  If I did something wrong, please
>let me know.  

I think it would be better to leave it as its own module.  That way you could
put it in or leave it out as you see fit, and you won't have to worry about any
weird interactions with mod_proxy.  Plus, it's more, well, modular.

>So, I recompiled the front-end like that.  I then edited
>PerlRun.pm, which I have set as my mod_perl in httpd.conf.  I assume this is
>what you meant.  I added the code you gave me to PerlRun.pm.
>
>Unfortunately, things aren't quite working right.  Shouldn't this
>implementation allow me to access REMOTE_ADDR as I normally do through
>environment variables?  I was unable to.  It's still listing localhost as
>the address.  Did I do something wrong?

You should be able to access REMOTE_ADDR as usual.  That probably means that
the C code isn't executing.  Try seperating the code out as its own module, as
recommended above.

Also try adding debug statements to the Perl & C code to see whether it's
executing.


>
>Furthermore, I really don't understand the PERL or the C... What exactly is
>r and connection here?  Sorry for my ignorance, but I'm kind of clueless as
>far as what these are.
>

Oh, looking at the code I gave you, you should change $::r to $r.  That's what
it's called in PerlRun.

$r is the Apache request object.  It's how you access all the server internals. 
Do 'perldoc Apache' for all the info.


>By the way, I've already done some testing and have seen that certain
>environment variables are preserved, so I'll just want to rewrite the C and
>PERL code to pass through the other variables.
>
>Thanks for your help,
>
>Russell
>
>
>> -----Original Message-----
>> From: modperl-owner@apache.org [mailto:modperl-owner@apache.org]On
>> Behalf Of Ken Williams
>> Sent: Sunday, February 28, 1999 2:17 AM
>> To: Russell D. Weiss
>> Cc: modperl@apache.org
>> Subject: RE: Proxying -- Loss of Environment Vars?
>>
>>
>> Hi Russell,
>>
>> Basically, that module adds an extra HTTP header to proxying
>> requests.  You can
>> access that header in the mod_perl-enabled server, and set
>> the IP of the remote
>> server.  You won't need to compile anything into the back-end
>> server, just put
>> something like the following into your mod_perl handler:
>>
>>     my $real_client;
>>     if (defined($real_client = $::r->header_in('X-Forwarded-For'))) {
>>             $::r->connection->remote_ip($real_client);
>>     }
>>
>> See how it works?  From that point on, the remote IP address
>> is correct.
>>
>> You could do the same thing with other environment variables
>> (though I think
>> several of them are preserved, you'll want to run some tests
>> to see which
>> ones).
>>
>>
>> rweiss@inforelay.com (Russell D. Weiss) wrote:
>> >Hey Ken,
>> >
>> >This very well might solve my problems, but I'm assuming I
>> have to also
>> >modify and recompile the "back-end" Apache so I can make use
>> of this?  I
>> >don't quite understand exactly what is going on here and how
>> the module
>> >works.  Then again, I don't know much about Apache
>> programming.  I wish I
>> >would have learned C first instead of just learning C++!
>> >
>> >Once I understand this module, I'll probably want to modify
>> it to pass
>> >through other environment variables.  Right now, I guess I'm
>> wondering if
>> >you could give me a brief explanation of how it works, and
>> how, exactly, I
>> >can access the "passed through" information with the back-end Apache.
>> >
>> >Thank you very much for your help,
>> >Russell
>> >
>> >> -----Original Message-----
>> >> From: modperl-owner@apache.org [mailto:modperl-owner@apache.org]On
>> >> Behalf Of Ken Williams
>> >> Sent: Sunday, February 28, 1999 12:04 AM
>> >> To: Russell D. Weiss
>> >> Cc: modperl@apache.org
>> >> Subject: Re: Proxying -- Loss of Environment Vars?
>> >>
>> >>
>> >> Hi Russell,
>> >>
>> >> This is one of the things that we just have to work around
>> >> for now.  The way we
>> >> work around it at the Math Forum is by using the following
>> >> custom apache module
>> >> that Ask wrote - it's appended at the bottom of this message.
>> >>  It's written in
>> >> C, so you'd compile it into your proxying server.
>> >>
>> >> I hope this solves your problem.
>> >>
>>
>>   -------------------                            -------------------
>>   Ken Williams                             Last Bastion of Euclidity
>>   ken@forum.swarthmore.edu                            The Math Forum
>>
>>

  -------------------                            -------------------
  Ken Williams                             Last Bastion of Euclidity
  ken@forum.swarthmore.edu                            The Math Forum

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic