nginxのhttp_geoip_moduleで国別アクセス制限の対応方法について

nginxのhttp_geoip_moduleを使うと国別アクセス制限ができるようです。
対応方法を教えてください。
2014-07-02 17:11 コメント
已邀请:

ベストアンサー

0

iQi - 面白いアプリを開発中

{ 賛成 }:

GeoIP更新用シェルを作成

cd /tmp

wget http://geolite.maxmind.com/dow ... ar.gz

tar -zxvf GeoIP.tar.gz

cd GeoIP-1.4.8

yum install zlib-devel

./configure

make

make install

echo '/usr/local/lib' > /etc/ld.so.conf.d/geoip.conf

ldconfig

ldconfig -v | less

wget http://geolite.maxmind.com/dow ... at.gz -O /usr/local/share/GeoIP/GeoIP.dat.gz

gunzip /usr/local/share/GeoIP/GeoIP.dat.gz




Nginx Compile

./configure --without-http_empty_gif_module --with-poll_module --with-http_stub_status_module --with-http_ssl_module --with-ipv6 --with-http_geoip_module

make

make install

※LNMPでインストールする場合、upgrade_nginx.shに「--with-http_geoip_module」を追加してから「./upgrade_nginx.sh」実行してください。


Nginx設定

SET the path to the .dat file used for determining the visitor's country from the IP-address

  geoip_country /usr/local/share/GeoIP/GeoIP.dat;

### SET FASTCGI Variables ###
fastcgi_param GEOIP_COUNTRY_CODE $geoip_country_code;
fastcgi_param GEOIP_COUNTRY_CODE3 $geoip_country_code3;
fastcgi_param GEOIP_COUNTRY_NAME $geoip_country_name;


/usr/local/nginx/sbin/nginx -s reload




PHP Test Script

<html>
<head>
<title>What is my IP address - determine or retrieve my IP address</title>
</head>
<body>
<?php
 if (getenv(HTTP_X_FORWARDED_FOR)) {
    $pipaddress = getenv(HTTP_X_FORWARDED_FOR);
    $ipaddress = getenv(REMOTE_ADDR);
    echo "Your Proxy IP address is : ".$pipaddress. " (via $ipaddress) " ;
} else {
    $ipaddress = getenv(REMOTE_ADDR);
    echo "Your IP address is : $ipaddress";
}
$country = getenv(GEOIP_COUNTRY_NAME);
$country_code = getenv(GEOIP_COUNTRY_CODE);
echo "<br/>Your country : $country ( $country_code ) ";
?>
</body>
</html>
2014-07-02 17:29 コメント

ログインまたは登録してから回答してください

lujian
lujian

Javaが得意です。

@ステータス

  • 更新: 2014-07-02 17:30
  • 閲覧: 3452
  • フォロー: 3
EXIT フルスクリーンモード 回答