nginxinc / docker-nginx

Official NGINX Dockerfiles
BSD 2-Clause "Simplified" License
3.25k stars 1.73k forks source link

Brotli support for nginx alpine image #371

Closed pumano closed 3 years ago

pumano commented 5 years ago

Would be good to have official nginx alpine docker image with brotli support with fall back to gzip.

Previously I found #210 issue with closed #216 PR. That PR closed due to issue where google/ngx_brotli want to drop support in 2017, but today looks like google/ngx_brotli now live! Previous fork eustas/ngx_brotli merged back to original repo.

Today all major browsers support brotli and that algorithm very efficient. Would be good to have brotli + nginx alpine docker image

thresheek commented 5 years ago

The point about not shipping third-party modules still stands though.

ai commented 4 years ago

@thresheek do we have right now any reason not to add Brotli support to nginx official modules? If there is some legal reason, could we make the exception of using a third-party module here? If there are no good reasons, how we can help in adding Brotli support to nginx?

Brotli looks like a great feature for performance, but right now there is no good Docker image with nginx and Brotli.

thresheek commented 4 years ago

The only way to add brotli to this image is to make it a part of an official nginx distribution. I see no way we can support that otherwise.

ai commented 4 years ago

@thresheek of course. I think that nginx should support Brotli by default.

What we can do to add official Brotli support? I saw batch in nginx tracker. Maybe there is a way to vote or pay to promote some feature?

thresheek commented 4 years ago

I would say sending a patch to the development mailing list would at least make sure developers could comment on it; however I see it was submitted in early 2017 with no real reply, which is frustrating.

thresheek commented 4 years ago

A viable option would be also to implement a "development image" as discussed in https://github.com/nginxinc/docker-nginx/issues/239 - it wouldnt have the effect of an image that will have all the modules built-in, but would it make easier for everyone to do their own images/build the modules they need.

pumano commented 4 years ago

@thresheek in 2017 nginx devs not accept it due to same reason, because google/ngx_brotli stop their development.

ai commented 4 years ago

because google/ngx_brotli stop their development.

Now it is not a problem, since Google continue development

pumano commented 4 years ago

We need to find some idea how to create official nginx image with brotli support.

It's looks like few additional strings in dockerfile, can provide huge positive impact on community.

Also de-facto best in class nginx web server just in win-win situation if support will be provided.

polarathene commented 4 years ago

You can add brotli support with your own alpine image easily enough afaik. Drawback is that you don't build from source, using the version of Alpines nginx package(current alpine:3.10 provides nginx 1.16.x).

I have not tried it yet, but they have quite a few modules are available as separate packages, you just install them with the nginx package and should have support. I've done similar with PHP.

I'm not entirely sure how that works if you're meant to compile them in like I've seen official nginx and PHP images do(building from source instead). But presumably if someone submitted a nginx-mod-brotli package and that got accepted, we'd have an easy way to use brotli module. AFAIK, right now we have to maintain a fork of this repos dockerfile?

Looks like they're included as dynamically linked modules to make them optional. Is that something that could be done here too?

eyalzek commented 4 years ago

A nice solution would be to create an official ONBUILD image that would allow developers to specify any additional modules which are not "officially" supported by the team, this way the responsibility of maintaining these modules wouldn't fall on the team itself, while developers would have a fairly straightforward way to build additional modules on top of the upstream image. Though I'm not really sure how simple it is to implement such an image.

mahnunchik commented 4 years ago

Any news?

thresheek commented 4 years ago

Nobody volunteered a solution so far.

As per ONBUILD, using those is discouraged: https://github.com/docker-library/official-images/issues/2076

tracker1 commented 4 years ago

Another possible solution, would be to add a brotli_static similar to gzip_static, so at least pre-compressed files could be served.

Herz3h commented 4 years ago

What are the alternatives to have brotli if it won't be included in the base image ?

gldraphael commented 4 years ago

If moving out of nginx is okay, caddy is a good alternative.

On Thu, Aug 20, 2020, 14:10 Ahmed El Moden notifications@github.com wrote:

What are the alternatives to have brotli if it won't be included in the base image ?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/nginxinc/docker-nginx/issues/371#issuecomment-677462095, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACSLJZPKXCFS53GHC3SOH33SBTOODANCNFSM4I7MJ7IQ .

Macil commented 4 years ago

@Herz3h The docker image fholzer/nginx-brotli has nginx with brotli support.

tracker1 commented 4 years ago

@Macil @Herz3h I've been using xddxdd/nginx myself... But had to make a couple config mods for my own needs. As I'm precompressing the files I need compressed so don't need dynamic compression at all.

SymbioticKilla commented 3 years ago

Still not on roadmap? brotli is already standard for web(text) compression...

Korijn commented 3 years ago

Sorry for the mean words, I removed them.

Edit: I found a way to minimally extend the official image with ngx_brotli support, see here: https://github.com/Korijn/docker-nginx-brotli

tsuna commented 3 years ago

Would be nice to get Brotli support upstream.

igor-adtrac commented 3 years ago

This is a must have feature.

ajslater commented 3 years ago

I think there's a drop-in nginx brotli module coming to alpine soon. https://pkgs.alpinelinux.org/package/edge/main/x86/nginx-mod-http-brotli Its been available since nginx-1.18.0-r5, so it may arrive with alpine v3.13

thresheek commented 3 years ago

Hi. I've added a way to make it easier to add modules on top of the official image, please check https://github.com/nginxinc/docker-nginx/tree/master/modules for more information.

georg-jung commented 1 year ago

Thanks @thresheek for creating that Dockerfile!

I created a GitHub Actions workflow that automatically checks for updates to the official nginx:mainline image daily and uses your Dockerfile to create a version including ngx_brotli if updates are available.

I make these fully automatically built images available at georgjung/nginx-brotli, if that might help anyone.

wokalek commented 1 year ago

You can use my lightweight nginx docker alpine-based image with brotli support

georg-jung commented 1 year ago

@wokalek Thanks for creating this, it's always better to have multiple options to choose from.

I created https://hub.docker.com/r/georgjung/nginx-brotli because I disliked most of the existing nginx-brotli images for becoming stale because they are manually maintained. For something as critical as a webserver it felt wrong to me that security patches could reach my servers weeks or months later if the maintainer (or: "some random dude on the internet") lost interest/is on holiday/... At the same time I fully understand and feel that keeping a close eye for regular maintenance tasks that aren't even about someone's own code (but nginx's) isn't the most fun thing to do as a freetime OSS contributor.

Nevertheless, while I wouldn't want to push anyone to use my image rather than yours, I wondered if there is any advantage in using your (manually created if I get it right?) image rather than the nginx-brotli:alpine variant of my automatically updated images?

wokalek commented 1 year ago

@georg-jung

Hey! Thanks for commenting on my work!

I came across your image on the Docker Hub and I remember that I tried to find the repository, but for some reason I didn’t find it with my eyes on Github (but now I took a closer look and got acquainted with it).

My image is positioned as a lightweight alternative to the original nginx image, but with brotli support.

I do not really like to enter into discussions "whose approach is better", but I will say a few words.

  1. If you are really interested, then you can compare the sizes of the resulting images. georgjung/nginx-brotli:1.25.1-alpine is 16.39 MB in size (gzip compressed). wokalek/nginx-brotli:1.25.1 is 9.36 MB, almost half that size. In this regard, your images do not differ from the official ones, just + brotli.

  2. I tried to thoroughly study the build process of the actual, latest version of nginx and did not use any extra configuration settings (unnecessary - too, which turned out to be a lot in other images). I don't think previous versions of nginx are really of interest to anyone using the server... Maybe I'm wrong, but I will support only versions from 1.25.1.

  3. You're right, automatic build is really cool. And I saw this not only in your repository, and I myself want to automate it when my hands reach it (: But when that will be, I can't say right now. Yes, at the moment I build images manually.

  4. I actively monitor OpenSSL and its HTTP3/QUIC support and plan to update my image (http3 branch) with the versions of these libraries as well (+ brotli). At the moment, this is a highly unstable technology that can only be used by enthusiasts, but I hope that it will soon become stable and the new standard.

  5. And perhaps the most important plus. In my repository there is a completely understandable and clean dockerfile, on the basis of which you can build your own nginx build with your modules. It is more suitable for familiarizing the process of building nginx than most other dockerfiles that I found on the Internet.

wokalek commented 1 year ago

Brotli is included in NGINX Plus, so it's never will be included in standard nginx (who knows...)

thresheek commented 1 year ago

@wokalek Brotli support in NGINX Plus is exactly the same what we ship via https://github.com/nginxinc/docker-nginx/tree/master/modules and pkg-oss. In fact, NGINX Plus build system uses pkg-oss for those modules.

wokalek commented 1 year ago

@wokalek Brotli support in NGINX Plus is exactly the same what we ship via https://github.com/nginxinc/docker-nginx/tree/master/modules and pkg-oss. In fact, NGINX Plus build system uses pkg-oss for those modules.

I mean it won't be included by default in a standard nginx build. You must specify it for the build yourself, or use NGINX Plus, if I understand everything correctly.

thresheek commented 1 year ago

Indeed. At least for now, there are no plans to include Brotli support in main nginx codebase.

ciprianmacovei commented 8 months ago

thank u @georg-jung for the nginx-brotli img :D works perfectly

opablo commented 5 months ago

This is what I had to do to add brotli and other modules to my official nginx docker image...

nginxcache/Dockerfile

FROM nginx:1.26.0-alpine

# deleting the limited (no extra modules) nginx 1.26.x installation
RUN apk del -r nginx

# installing the alpine os native nginx 1.24.0 with the extra modules we need
RUN apk add --no-cache \
  nginx \
  nginx-mod-http-vts \
  nginx-mod-http-brotli \
  nginx-mod-http-cache-purge \
  nginx-mod-http-headers-more

docker-compose.yml

  nginxcache:
    build:
      context: nginxcache
    container_name: nginxcache-dev
    restart: unless-stopped
    volumes:
      - nginxcache:/var/cache/nginx
      - ./nginxcache/nginx.conf:/etc/nginx/nginx.conf
      - ./nginxcache/localhost.crt:/etc/ssl/localhost.crt
      - ./nginxcache/localhost.key:/etc/ssl/localhost.key

you can trigger the creation of such local image using: docker-compose build before running docker-compose up

it's wrong... it's not really what I want... it's actually using the nginx compiled by alpine and not the nginx compiled by nginx team... but this hack is what I'm using while I wait for the nginx team to provide a better solution to have an official image with official brotli support

again.. it's not what I really want... but sharing what I am currently doing in case it's of use to others