[英]Installing GeoIP module for latest NGINX for Docker
I am trying to create a docker image which contains a nginx service with GeoIP module. 我正在尝试创建一个包含带有GeoIP模块的nginx服务的docker映像。 As far as I tried, running
apt-get install nginx
with any flags doesn't help to include the --with-http_geoip_module
module in the nginx installed. 据我所试,运行带有任何标志的
apt-get install nginx
都无助于在安装的nginx中包括--with-http_geoip_module
模块。 Therefore, I tried to installed it from the nginx source 因此,我尝试从nginx源安装它
add-apt-repository ppa:nginx/development -y \
&& echo "deb-src http://ppa.launchpad.net/nginx/development/ubuntu xenial main" >> /etc/apt/sources.list \
&& apt-get update \
&& apt-get build-dep nginx -y \
&& cd /opt \
&& mkdir tempnginx \
&& cd tempnginx \
&& apt-get source nginx \
and so on and so on 等等等等
The GeoIP doesn't work as it should, as I tried to put it on the log as like this : GeoIP无法正常工作,因为我试图将其记录在日志中,如下所示:
nginx.conf nginx.conf
user www-data;
worker_processes 1;
load_module modules/ngx_http_geoip_module.so;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
geoip_country /usr/share/GeoIP/GeoIP.dat;
geoip_city /usr/share/GeoIP/GeoLiteCity.dat;
log_format main '$remote_addr - [$time_local] '
'"$request" $status $bytes_sent $request_time $upstream_response_time'
'"$http_referer" "$http_user_agent" "$gzip_ratio" '
'"$geoip_region" "$geoip_city" "$geoip_city_country_code"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
}
The log will just print those GeoIP parameters as "-" 日志只会将那些GeoIP参数打印为“-”
Any idea why it doesn't work? 知道为什么它不起作用吗? The Nginx version should be the latest one.
Nginx版本应该是最新版本。
-- edit -- -编辑-
Add the result from running nginx -V 添加运行nginx -V的结果
nginx version: nginx/1.13.3
built with OpenSSL 1.0.2g 1 Mar 2016
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now -fPIC' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_geoip_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_xslt_module=dynamic --with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --with-mail=dynamic --with-mail_ssl_module --add-dynamic-module=/opt/tempnginx/nginx-1.13.3/debian/modules/nginx-auth-pam --add-dynamic-module=/opt/tempnginx/nginx-1.13.3/debian/modules/nginx-dav-ext-module --add-dynamic-module=/opt/tempnginx/nginx-1.13.3/debian/modules/nginx-echo --add-dynamic-module=/opt/tempnginx/nginx-1.13.3/debian/modules/nginx-upstream-fair --add-dynamic-module=/opt/tempnginx/nginx-1.13.3/debian/modules/ngx_http_substitutions_filter_module
modules 模块
modules
path=/usr/lib/nginx/modules
http_ssl_module
http_stub_status_module
http_realip_module
http_auth_request_module
http_v2_module
http_dav_module
http_slice_module
http_addition_module
http_geoip_module
http_gunzip_module
http_gzip_static_module
http_image_filter_module=dynamic
http_sub_module
http_xslt_module=dynamic
stream_ssl_module
stream_ssl_preread_module
mail_ssl_module
module=/opt/tempnginx/nginx
1.13.3/debian/modules/nginx
module=/opt/tempnginx/nginx
1.13.3/debian/modules/nginx
module
module=/opt/tempnginx/nginx
1.13.3/debian/modules/nginx
module=/opt/tempnginx/nginx
1.13.3/debian/modules/nginx
module=/opt/tempnginx/nginx
1.13.3/debian/modules/ngx_http_substitutions_filter_module
It turned out that the installation is working, and I just realised that I tried to access it from localhost, which means the IP becomes unresolved. 事实证明该安装正在运行,并且我刚刚意识到我试图从localhost访问它,这意味着IP变得无法解析。 After trying on remote host, the GeoIP module works fine :)
在远程主机上尝试后,GeoIP模块可以正常工作:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.