Search code examples
nginxalpine-linuxmusl

Static build of Nginx


I am preparing a Docker image that intends to use a static build of Nginx

RUN set -ex \
    && wget -qO- github.com/nginx/nginx/archive/"$NGINX_HASH".tar.gz | tar zx --strip-components=1 \
    && ./auto/configure --without-http_rewrite_module --without-http_gzip_module \
    && make CFLAGS="-O2 -s" LDFLAGS="-static" -j$(nproc) \
    && ldd ./objs/nginx

Unfortunately, even with the flags -static it seems to be linked against musl

ldd ./objs/nginx
    /lib/ld-musl-x86_64.so.1 (0x7fcce5ebe000)
    libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7fcce5ebe000)

What do I need to do to link statically?


Solution

  • Solved with

    RUN ./auto/configure --without-http_rewrite_module --without-http_gzip_module --with-cc-opt="-O2" --with-ld-opt="-s -static"