How to compile Nginx with zlib-ng

Richard Stanway r1ch+nginx at teamliquid.net
Thu Mar 23 20:33:19 UTC 2023


Yes, when using the latest zlib-ng on nginx-1.21.6 I received the
alerts. Previous versions of zlib-ng have worked great after the 2021
patch. I tried to update it myself as follows based on advice of
zlib-ng GitHub issues, while it reduced the number of alerts logged it
did not completely solve the issue so it seems the memory requirements
may have further changed. While I would appreciate a proper patch
making it into nginx, the seemingly-frequent upstream changes may make
this difficult to maintain.

-        ctx->allocated = 8192 + 16 + (1 << (wbits + 2))
+        ctx->allocated = 8192 + 288 + 16 + (1 << (wbits + 2))
                          + 131072 + (1 << (memlevel + 8));


On Thu, 23 Mar 2023 at 04:16, Lance Dockins <lance at wordkeeper.com> wrote:
>
> Thank you, Richard.  I’ll give that a shot.   I already have to do that sort of patching with a variety of other things in the build that I use so that particular adjustment isn’t too bad.
>
> Just for clarity, are you saying that the hash sizes within zlib-ng have increased since Maxim’s last patch for that to accommodate zlib-ng?  That patch was back in 2021 and is part of Nginx core now.
> https://mailman.nginx.org/pipermail/nginx-devel/2021-April/013945.html
>
> I think it’s coded to use a 128k hash per that patch.  If the hash size has increased again since that patch, that might justify a bug report to Nginx devel.  Since the code in that patch specifically relates to that error, I thought I’d ask in case you have still been seeing that error with newer Nginx versions that have come out since that patch was implemented.
>
>
> --
> Lance
>
> On Mar 22, 2023 at 5:28 PM -0500, Richard Stanway via nginx <nginx at nginx.org>, wrote:
>
> I regularly build with zlib-ng, unfortunately it requires patching the zlib-ng files to enable zlib compatibility mode as nginx doesn't seem to have a way to pass options to configure.
>
> Edit "configure" in the zlib-ng directory and change the line compat=0 to compat=1. Then specify --with-zlib=/path/to/zlib-ng in your nginx configure and you should be set.
>
> Be aware that the memory requirements of zlib-ng have changed since support for it was added to nginx, so you will see a lot of "gzip filter failed to use preallocated memory" alerts in your log file when using zlib-ng.
>
>
> On Wed, 22 Mar 2023 at 15:50, Sergey A. Osokin <osa at freebsd.org.ru> wrote:
>>
>> Hi Lance,
>>
>> thanks for your question.
>>
>> Since this is more or less related to nginx development or
>> new features I'd suggest to use nginx-devel mailing list
>> instead, thank you.
>>
>> On Tue, Mar 21, 2023 at 04:06:00PM -0500, Lance Dockins wrote:
>> >
>> > Has anyone had success compiling Nginx with zlib-ng instead of
>> > default Zlib versions?  I seem to be able to compile Nginx with
>> > standard Zlib and various other Zlib libraries (e.g. Intel
>> > optimized or Cloudflare) but compiling with Zlib-NG always fails.
>>
>> NGINX builds well with zlib.  In case of new functionality, like
>> an ability to build with zlib-ng, the source code requires some
>> patches.
>>
>> > I’ve tried passing in various options via with-zlib-opt to try
>> > to include the —zlib-compat flag for the Zlib NG configure
>> > directives but no matter what syntax I use, it seems like it
>> > always fails (whether I have that param or not).  Perhaps I’m
>> > just struggling with the proper use of Zlib NG in an Nginx
>> > compile context.
>> >
>> > If Nginx should compile with Zlib NG, is there any documentation
>> > on what params to use in the Nginx compile command to get it to
>> > work?
>>
>> Some ideas can be found inside the zlib-ng project on GH, not
>> sure is that working solution or not, so you can try.
>>
>> I'd also recommend to raise a request in https://trac.nginx.org/nginx/
>> about this feature request and provide patches for source code
>> and documentation.
>>
>> Thank you.
>>
>> --
>> Sergey A. Osokin
>> _______________________________________________
>> nginx mailing list
>> nginx at nginx.org
>> https://mailman.nginx.org/mailman/listinfo/nginx
>
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> https://mailman.nginx.org/mailman/listinfo/nginx


More information about the nginx mailing list