|
| 1 | +FROM nginxproxy/nginx-proxy AS builder |
| 2 | + |
| 3 | +ENV GEOIP2_VERSION=3.4 |
| 4 | + |
| 5 | +# 安装编译依赖并编译 GeoIP2 模块 |
| 6 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 7 | + build-essential \ |
| 8 | + libpcre3-dev \ |
| 9 | + zlib1g-dev \ |
| 10 | + libgeoip-dev \ |
| 11 | + libmaxminddb-dev \ |
| 12 | + wget \ |
| 13 | + git \ |
| 14 | + && cd /opt \ |
| 15 | + && git clone --depth 1 -b $GEOIP2_VERSION --single-branch https://github.com/leev/ngx_http_geoip2_module.git \ |
| 16 | + && wget -O - http://nginx.org/download/nginx-$NGINX_VERSION.tar.gz | tar xzf - \ |
| 17 | + && cd nginx-$NGINX_VERSION \ |
| 18 | + && ./configure --with-compat --add-dynamic-module=/opt/ngx_http_geoip2_module \ |
| 19 | + && make modules |
| 20 | + |
| 21 | +# 最终镜像 |
1 | 22 | FROM nginxproxy/nginx-proxy |
2 | | -RUN { \ |
3 | | - echo 'server_tokens off;'; \ |
4 | | - echo 'client_max_body_size 1024m;'; \ |
5 | | - echo 'proxy_buffer_size 256k;'; \ |
6 | | - echo 'proxy_buffers 4 256k;'; \ |
7 | | - echo 'proxy_busy_buffers_size 256k;'; \ |
8 | | - echo 'proxy_hide_header X-Generator;'; \ |
9 | | - echo 'client_header_buffer_size 64k;'; \ |
10 | | - echo 'large_client_header_buffers 4 64k;'; \ |
11 | | - echo 'proxy_connect_timeout 300;'; \ |
12 | | - echo 'proxy_send_timeout 300;'; \ |
13 | | - echo 'proxy_read_timeout 300;'; \ |
14 | | - echo 'send_timeout 300;'; \ |
15 | | - } > /etc/nginx/conf.d/my_proxy.conf |
| 23 | + |
| 24 | +# 复制编译好的模块 |
| 25 | +COPY --from=builder /opt/nginx-*/objs/ngx_http_geoip2_module.so /usr/lib/nginx/modules/ |
| 26 | + |
| 27 | +# 安装运行时依赖并下载 GeoIP 数据库 |
| 28 | +RUN apt-get update \ |
| 29 | + && apt-get install -y --no-install-recommends libmaxminddb0 wget \ |
| 30 | + && apt-get clean \ |
| 31 | + && rm -rf /var/lib/apt/lists/* \ |
| 32 | + && chmod 644 /usr/lib/nginx/modules/ngx_http_geoip2_module.so \ |
| 33 | + && sed -i '1iload_module /usr/lib/nginx/modules/ngx_http_geoip2_module.so;' /etc/nginx/nginx.conf \ |
| 34 | + && mkdir -p /usr/share/geoip \ |
| 35 | + && wget -O /usr/share/geoip/GeoLite2-Country.mmdb https://github.com/P3TERX/GeoLite.mmdb/raw/download/GeoLite2-Country.mmdb \ |
| 36 | + && wget -O /usr/share/geoip/GeoLite2-City.mmdb https://github.com/P3TERX/GeoLite.mmdb/raw/download/GeoLite2-City.mmdb |
| 37 | + |
| 38 | +COPY rootfs/etc/nginx/conf.d/my_proxy.conf /etc/nginx/conf.d/my_proxy.conf |
| 39 | +COPY rootfs/etc/nginx/conf.d/geoip2.conf /etc/nginx/conf.d/geoip2.conf |
16 | 40 | ADD https://raw.githubusercontent.com/h5bp/server-configs-nginx/main/h5bp/web_performance/compression.conf /etc/nginx/conf.d/compression-gzip.conf |
0 commit comments