【问题标题】:How to enable a native module in nginx alpine docker image如何在 nginx alpine docker 映像中启用本机模块
【发布时间】:2021-04-10 03:52:42
【问题描述】:

我想使用http://nginx.org/en/docs/http/ngx_http_realip_module.html 指示启用--with-http_realip_module 使用它。

我正在使用docker来使用这个nginx

FROM nginx:alpine

COPY default.conf /etc/nginx/conf.d/default.conf

现在如何在这个 docker 中启用这个模块?我可以在docker run 时传递一些参数或者我需要更改 dockerfile 吗?

【问题讨论】:

    标签: docker nginx dockerfile nginx-reverse-proxy nginx-config


    【解决方案1】:

    nginx 是not built with --with-http_realip_module by default

    可以通过检查nginx:alpine docker images来验证模块是否构建

    $ docker run --rm nginx:alpine nginx -V
    /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
    /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
    /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
    10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
    10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
    /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
    /docker-entrypoint.sh: Configuration complete; ready for start up
    nginx version: nginx/1.19.6
    built by gcc 9.3.0 (Alpine 9.3.0)
    built with OpenSSL 1.1.1g  21 Apr 2020 (running with OpenSSL 1.1.1i  8 Dec 2020)
    TLS SNI support enabled
    configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --with-perl_modules_path=/usr/lib/perl5/vendor_perl --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-Os -fomit-frame-pointer' --with-ld-opt=-Wl,--as-needed
    

    你可以看到--with-http_realip_module在那里。

    您需要做的就是configure nginx appropriately (in nginx.conf)

    例如:

    set_real_ip_from  192.168.1.0/24;
    set_real_ip_from  192.168.2.1;
    set_real_ip_from  2001:0db8::/32;
    real_ip_header    X-Forwarded-For;
    real_ip_recursive on;
    

    【讨论】:

    • 好的。知道了。但是为什么在官方文档中他们写的这个模块不是默认构建的? nginx.org/en/docs/http/ngx_http_realip_module.html
    • @coderelliot:抱歉,我打错了。谢谢你指出,我已经更正了。我很高兴它帮助了你:)
    猜你喜欢
    • 2019-04-02
    • 1970-01-01
    • 2017-11-30
    • 1970-01-01
    • 1970-01-01
    • 2021-11-12
    • 1970-01-01
    • 2016-09-08
    • 2021-11-07
    相关资源
    最近更新 更多