LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 10-04-2014, 04:08 AM   #1
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,307
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
How to replace content of REMOTE_ADDR header in Apache2


What is a way to replace the content of the REMOTE_ADDR header in Apache2 with out resorting to rpaf?
 
Old 10-04-2014, 05:04 AM   #2
Doc CPU
Senior Member
 
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 1,099

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Hi there,

Quote:
Originally Posted by Turbocapitalist View Post
What is a way to replace the content of the REMOTE_ADDR header in Apache2 with out resorting to rpaf?
to be honest, I don't really understand what you're going to do, neither for what reason. On top of that, your wording is inaccurate.

Actually, REMOTE_ADDR isn't a header (you probably mean an HTTP request or response header). Instead, it's an environment variable that Apache passes to a CGI, and its value is the IP address of the client initiating the request. For instance, if you're using PHP, you can access this information through $_SERVER['REMOTE_ADDR']. In Perl, you'd access this directly as an environment variable, I think (don't know much about Perl, though).

So what precisely do you wish to replace? With what else? And for what purpose?
Maybe there's a misunderstanding on your behalf, and the adequate solution could be completely different from what you think.

[X] Doc CPU
 
Old 10-04-2014, 05:35 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,307

Original Poster
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
If you have this network:

Code:
Internet -- proxy/cache -- apache2
All the scripts and modules in Apache2 see incoming connections as only from proxy/cache, not their original source. This applies to modules on Apache

If using PHP, then $_SERVER['REMOTE_ADDR'] would contain the address of the proxy/cache and not the actual client address. The correct client address is in $_SERVER['HTTP_X_FORWARDED_FOR'] so I would like Apache2 itself to fill in the content of REMOTE_ADDR with that of HTTP_X_FORWARDED_FOR

For example, you can see it in the log file format. This will show in the first column the address of the proxy/cache:

Code:
LogFormat "%h %l %u %t \"%r\" %>s %b" common
and in contrast this one will show the correct address of the client in the first column:

Code:
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b" common
Again, modules get passed "%h" and I need them to receive "%{X-Forwarded-For}i". Since some are hard-coded to read "%h", I seem to need to replace the contents of "%h" with the right value.
 
Old 10-04-2014, 05:57 AM   #4
Doc CPU
Senior Member
 
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 1,099

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Hi there,

Quote:
Originally Posted by Turbocapitalist View Post
If you have this network:

Code:
Internet -- proxy/cache -- apache2
ah, I see. You should've mentioned the use of a proxy in your previous post.
True, in that setup, REMOTE_ADDR indicating the proxy's IP is a useless information, though technically correct.

Quote:
Originally Posted by Turbocapitalist View Post
All the scripts and modules in Apache2 see incoming connections as only from proxy/cache, not their original source.
Bear in mind that this may be a desired effect - at least if the client uses a proxy deliberately. If the proxy is part of your own infrastructure, however, you don't gain anything in terms of information.

Quote:
Originally Posted by Turbocapitalist View Post
If using PHP, then $_SERVER['REMOTE_ADDR'] would contain the address of the proxy/cache and not the actual client address. The correct client address is in $_SERVER['HTTP_X_FORWARDED_FOR'] so I would like Apache2 itself to fill in the content of REMOTE_ADDR with that of HTTP_X_FORWARDED_FOR
I understand this now. Unfortunately, I can't think of a way to do it, because I'm afraid this behavior is kind of hardwired inside Apache. Or more to the point, it's the result of Apache's not caring whether the apparent client is a proxy. From Apache's view, the proxy requests a resource, so the proxy gets it, and it's the proxy's task to forward it back[*] to the original client. Apache doesn't care.

Quote:
Originally Posted by Turbocapitalist View Post
Again, modules get passed "%h" and I need them to receive "%{X-Forwarded-For}i". Since some are hard-coded to read "%h", I seem to need to replace the contents of "%h" with the right value.
And to do so, you'll probably have to mess with Apache's source code and recompile your own. I'll gladly withdraw that assumption as soon as anybody comes up with a clever idea, but I doubt if they will ...

[X] Doc CPU


[*] Isn't that a paradox, "to forward it back"? ;-)
 
Old 10-06-2014, 08:54 AM   #5
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,307

Original Poster
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
Actually there are APIs for the modules to use to interact with Apache so it is a rare occasion that the source code itself needs to be messed with.

After some experimentation, and quite a bit of searching, there does not seem to any method to modify the Apache configuration file by itself to get that change. But there is a second module, mod_extract_forwarded, in addition to rpaf. Neither appear to have had much activity of late.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] replace the content in file sunilsagar Programming 7 07-25-2011 02:53 AM
Content-type header in php missing xlq Linux - Server 2 03-15-2007 08:06 AM
How to forward packets based on HTTP header content? varange Linux - Networking 4 11-24-2006 02:39 PM
content-length HTTP header MPowers Linux - Software 0 04-07-2006 03:01 PM
header file to replace conio.h Digital Surgeon Programming 1 03-29-2006 08:40 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 05:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration