为最新的NGINX for Docker安装GeoIP模块

时间:2017-08-01 09:40:15

标签: docker nginx networking devops geoip

我正在尝试创建一个包含带GeoIP模块的nginx服务的docker镜像。据我所知,使用任何标志运行#include<stdio.h> int prod(int num1,int num2) { static int num_old =0; static int i=0; static int somma =0; if (num2==0||num1==0) { return(num1*num2); } else { if(num2==1) return somma; if(i==0) num_old =num1; i++; somma = num1+num_old; prod(somma,num2-1); } } int main(){ int n1,n2; printf("Enter two numbers to find their product:\n"); scanf("%d" ,&n1); scanf("%d" ,&n2); printf("Product of %d and %d is %d",n1,n2,prod(n1,n2)); return 0; } 并不会有助于在安装的nginx中包含apt-get install nginx模块。因此,我尝试从nginx源安装它

--with-http_geoip_module

依旧等等

GeoIP并没有按预期工作,因为我试图将它放在日志中,如下所示:

nginx.conf

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 \

日志只会将这些GeoIP参数打印为&#34; - &#34;

知道它为什么不起作用? Nginx版本应该是最新版本。

- 编辑 -

添加运行nginx -V

的结果
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;

}

模块

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

1 个答案:

答案 0 :(得分:0)

原来,安装工作正常,我才意识到我试图从localhost访问它,这意味着IP无法解析。尝试远程主机后,GeoIP模块工作正常:)