Re: REMOTE_ADDR not working
by rowdog (Curate) on Jan 30, 2011 at 04:21 UTC
|
I haven't ever dealt with Amazon and I don't know much about web proxies but it sounds like you're getting a proxy address for all the requests. Maybe Amazon is running a reverse proxy?
Well, if I'm right, there should be other headers you can use. One way to check would be to dump %ENV and see if you find any proxy headers.
| [reply] |
|
Most likely Amazon are running a load balancer, so that if you have multiple machines running the same http server, the load gets shared between them automatically. It also allows Amazon to save on public routeable IP addresses, which as we know are becoming a scarce resource.
As others have said, you need to examine the headers, to look for one that contains the original IP address. Most likey it will be HTTP_X_FORWARDED_FOR, but it is entirely possible that Amazon have decided to do their own thing.
The other thing to be aware of is that your clients will most likely be behind a proxy from their ISP, so you are unlikely to see their real IP address. If you are lucky, the proxy at the client end will also have put the IP address in a special header. The other possibility is that both proxies put the IP addresses in HTTP_X_FORWARDED_FOR, to create a comma separated list of IP addresses.
| [reply] [d/l] [select] |
Re: REMOTE_ADDR not working
by dont_you (Hermit) on Jan 30, 2011 at 08:12 UTC
|
This is probably caused by a proxy server, so check the content of $ENV{HTTP_X_FORWARDED_FOR} | [reply] |
Re: REMOTE_ADDR not working
by hsinclai (Deacon) on Jan 30, 2011 at 16:31 UTC
|
$ENV{'REMOTE_ADDR'}
works fine as intended on a single machine with a public Elastic IP assigned.. if you have instances behind ELB, then X_HTTP_FORWARDED_FOR might work but I am not 100% sure they set that header... they must or else server logs would be messed up too.
| [reply] [d/l] [select] |
|
I know that ELB is used.
/*
sure they set that header... they must or else server logs would be messed up too.
*/
Could you please clarify
| [reply] |
|
vit,
If you know your server is behind ELB, then you should be in luck, need to read some docs:) maybe start here, but I'd like to note this has nothing to do with Perl!
ELB does pass HTTP_X_FORWARDED_FOR, which should be a start.
| [reply] |
Re: REMOTE_ADDR not working
by Jeppe (Monk) on May 03, 2017 at 07:42 UTC
|
REMOTE_ADDR breaks when there is a proxy involved. A better way is to first check for X-FORWARDED-FOR in the HTTP headers using $q->http('X-FORWARDED-FOR'). Proxies should set this field. Take note that there may be several comma-separated entries in that field. If that field is not set, get the IP from REMOTE_ADDR. | [reply] |
Re: REMOTE_ADDR not working
by Khen1950fx (Canon) on Jan 30, 2011 at 05:51 UTC
|
#!/usr/bin/perl -T
use strict;
use warnings;
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use Socket;
print header;
print start_html("Remote Host");
my $ip = 'localhost';
my $hostname = gethostbyaddr(inet_aton($ip), AF_INET);
print "Welcome, visitor from $hostname!<p>\n";
print end_html;
| [reply] [d/l] |
|
How would that yield a different IP?
| [reply] |