Apache-GeoIP
view release on metacpan or search on metacpan
Apache/Geo/Mirror.pm view on Meta::CPAN
use Apache::Geo::Mirror;
use strict;
sub handler {
my $r = Apache::Geo::Mirror->new(shift);
# continue along
}
The directives in F<httpd.conf> are as follows:
<Location /mirror>
PerlSetVar GeoIPDBFile "/usr/local/share/GeoIP/GeoIP.dat"
PerlSetVar GeoIPFlag Standard
PerlSetVar GeoIPMirror "/usr/local/share/data/mirror.txt"
PerlSetVar GeoIPDefault "http://www.cpan.org"
# other directives
</Location>
The directives available are
=over 4
=item PerlSetVar GeoIPDBFile "/path/to/GeoIP.dat"
This specifies the location of the F<GeoIP.dat> file.
If not given, it defaults to the location specified
upon installing the module.
=item PerlSetVar GeoIPFresh 5
This specifies a minimum freshness that the chosen mirror must satisfy.
If this is not specified, a value of 0 is assumed.
=item PerlSetVar GeoIPMirror "/path/to/mirror.txt"
This specifies the location of a file containing
the list of available mirrors. No default location for this file is assumed.
This file contains a list of mirror sites and the corresponding
country code in the format
http://some.server.com/some/path us
ftp://some.other.server.fr/somewhere fr
An optional third field may be specified, such as
ftp://some.other.server.ca/somewhere ca 3
where the third number indicates the freshness of the mirror. A default
freshness of 0 is assumed when none is specified. When choosing a mirror,
if the I<GeoIPFresh> directive is specified, only those mirrors
with a freshness equal to or above this value may be chosen.
=item PerlSetVar GeoIPDefault "http://some.where.org/"
This specifies the default url to be used if no nearby mirror is found.
Multiple values may be specified using I<PerlAddVar>; if more than one
default is given, a random one will be chosen.
=item PerlSetVar GeoIPXForwardedFor 1
If this directive is set to something true, the I<X-Forwarded-For> header will
be used to try to identify the originating IP address; this is useful for clients
connecting to a web server through an HTTP proxy or load balancer. If this header
is not present, C<$r-E<gt>connection-E<gt>remote_ip> will be used.
=back
=head1 METHODS
The available methods are as follows.
=over 4
=item $mirror = $r->find_mirror_by_country( [$country] );
Finds the nearest mirror by country code. If I<$country> is not
given, this defaults to the country as specified by a lookup
of C<$r-E<gt>connection-E<gt>remote_ip>.
=item $mirror = $r->find_mirror_by_addr( [$ipaddr] );
Finds the nearest mirror by IP address. If I<$ipaddr> is not
given, the value obtained by
examining the I<X-Forwarded-For> header will be used, if
I<GeoIPXForwardedFor> is used, or else
C<$r-E<gt>connection-E<gt>remote_ip> is used.
=item $gm = $r->gm;
Returns the L<Geo::IP::Mirror> object.
=back
=head1 AUTOMATIC REDIRECTION
If I<Apache::Geo::Mirror> is used as
PerlModule Apache::Geo::Mirror
<Location /CPAN>
PerlSetVar GeoIPDBFile "/usr/local/share/geoip/GeoIP.dat"
PerlSetVar GeoIPFlag Standard
PerlSetVar GeoIPMirror "/usr/local/share/data/mirror.txt"
PerlSetVar GeoIPDefault "http://www.cpan.org"
PerlHandler Apache::Geo::Mirror->auto_redirect
</Location>
then an automatic redirection is made. Within this, the directive
PerlSetVar GeoIPRobot "/path/to/a/robots.txt"
can be used to handle robots that honor a I<robots.txt> file. This can be
a physical file that exists on the system or, if it is set to the special
value I<default>, the string
User-agent: *
Disallow: /
will be used, which disallows robot access to anything.
Within automatic redirection, the I<X-Forwarded-For> header wil be
used to try to infer the IP address of the client.
=head1 SEE ALSO
L<Geo::IP>, L<Geo::Mirror>, and L<Apache>.
=head1 AUTHOR
The look-up code for associating a country with an IP address
is based on the GeoIP library and the Geo::IP Perl module, and is
Copyright (c) 2002, T.J. Mather, E<lt> tjmather@tjmather.com E<gt>, New York, NY,
USA. See http://www.maxmind.com/ for details. The mod_perl interface is
Copyright (c) 2002, 2009 Randy Kobes E<lt> randy.kobes@gmail.com E<gt>.
All rights reserved. This package is free software; you can redistribute it
and/or modify it under the same terms as Perl itself.
=cut
( run in 1.313 second using v1.01-cache-2.11-cpan-39bf76dae61 )