在 OS X 和 Ubuntu 下,我通过 nginx 在 PHP 中使用 GeoIP,如下所示:
nginx.conf:
geoip_country /somepath/GeoIP/GeoIP.dat;
fastcgi_param GEOIP_COUNTRY_CODE $geoip_country_code;
php:
$country = $_SERVER["GEOIP_COUNTRY_CODE"]
但是在 Alpine Linux 下,nginx ( apk add nginx
) 的包版本似乎不包含 GeoIP(由 确认nginx -V
)。
我可以从源代码编译 nginx --with-http_geoip_module
,但是我必须手动更新 nginx,这是不可取的。我目前的解决方法如下:
ash:
sudo apk add geoid
php:
$country = exec("geoiplookup $_SERVER[REMOTE_ADDR]");
如何在 Alpine Linux 下的 nginx 中获得原生 GeoIP 支持?
更新:geoip_country
即使我从边缘安装也无法识别。
$ apk update
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/main/x86_64/APKINDEX.tar.gz
v3.4.4-36-ge528256 [http://dl-cdn.alpinelinux.org/alpine/v3.4/main]
v3.4.0-4239-gff0f660 [http://dl-cdn.alpinelinux.org/alpine/edge/community]
v3.4.0-4267-ga3e3a29 [http://dl-cdn.alpinelinux.org/alpine/edge/main]
OK: 12899 distinct packages available
$ apk add nginx@edge nginx-mod-http-geoip@edge
(1/5) Installing libressl2.4-libcrypto@edge (2.4.3-r1)
(2/5) Installing pcre (8.38-r1)
(3/5) Installing libressl2.4-libssl@edge (2.4.3-r1)
(4/5) Installing nginx@edge (1.10.1-r9)
Executing nginx-1.10.1-r9.pre-install
(5/5) Installing nginx-mod-http-geoip@edge (1.10.1-r9)
Executing busybox-1.24.2-r11.trigger
OK: 500 MiB in 92 packages
$ rc-service nginx restart
* Caching service dependencies ... [ ok ]
nginx: [emerg] unknown directive "geoip_country" in /etc/nginx/nginx.conf:1
nginx: configuration file /etc/nginx/nginx.conf test failed [ !! ]
* ERROR: nginx failed to start