Skip to content

We-Amp/ngx-pagespeed-alpine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 

Repository files navigation

This repo has been moved to the offcicial Apache ngx_pagespeed repo.

[https://github.com/apache/incubator-pagespeed-ngx/tree/master/docker]

Supported tags and respective Dockerfile links

Quick reference

What is pagespeed?

The PageSpeed Modules, mod_pagespeed and ngx_pagespeed, are open-source webserver modules that optimize your site automatically.

ngx_pagespeed speeds up your site and reduces page load time by automatically applying web performance best practices to pages and associated assets (CSS, JavaScript, images) without requiring you to modify your existing content or workflow. Features include:

  • Image optimization: stripping meta-data, dynamic resizing, recompression
  • CSS & JavaScript minification, concatenation, inlining, and outlining
  • Small resource inlining
  • Deferring image and JavaScript loading
  • HTML rewriting
  • Cache lifetime extension
  • and more

To see ngx_pagespeed in action, with example pages for each of the optimizations, see our demonstration site.

logo

What is nginx?

Nginx (pronounced "engine-x") is an open source reverse proxy server for HTTP, HTTPS, SMTP, POP3, and IMAP protocols, as well as a load balancer, HTTP cache, and a web server (origin server). The nginx project started with a strong focus on high concurrency, high performance and low memory usage.

wikipedia.org/wiki/Nginx

What is nginx-pagespeed?

The nginx-pagespeed brings all the goods of nginx and pagespeed together in one single small alpine docker image. Nginx-pagespeed aims to be 100% compatible with the plain nginx images. Meaning, nginx-pagespeed can be a safe drop-in replacement for any container running nginx:alpine.

Nginx-pagespeed makes it easy to start optimizing your website by reducing page load time, without requiring you to modify existing content.

How to use this image

Hosting some simple static content

$ docker run --name pagespeed-nginx -v /some/content:/usr/share/nginx/html:ro -d pagespeed/nginx-pagespeed

Alternatively, a simple Dockerfile can be used to generate a new image that includes the necessary content (which is a much cleaner solution than the bind mount above):

FROM pagespeed/nginx-pagespeed
COPY static-html-directory /usr/share/nginx/html

Place this file in the same directory as your directory of content ("static-html-directory"), run docker build -t some-content-ngxpagespeed ., then start your container:

$ docker run --name my-nginx-pagespeed -d some-content-ngxpagespeed

Exposing external port

$ docker run --name my-nginx-pagespeed -d -p 8080:80 some-content-ngxpagespeed

Then you can hit http://localhost:8080 or http://host-ip:8080 in your browser.

Complex configuration

$ docker run --name my-custom-nginx-pagespeed -v /host/path/nginx.conf:/etc/nginx/nginx.conf:ro -d pagespeed/nginx-pagespeed

For information on the syntax of the nginx configuration files, see the official documentation (specifically the Beginner's Guide). For pagespeed specific nginx config syntax, see Beginner's guide or a complete overview of all pagespeed filters. For a quick start on pagespeed specific configuration see []

If you wish to adapt the default configuration, use something like the following to copy it from a running nginx-pagespeed container:

$ docker run --name tmp-ngxpagespeed-container -d pagespeed/nginx-pagespeed
$ docker cp tmp-ngxpagespeed-container:/etc/nginx/nginx.conf /host/path/nginx.conf
$ docker rm -f tmp-ngxpagespeed-container

This can also be accomplished more cleanly using a simple Dockerfile (in /host/path/):

FROM pagespeed/nginx-pagespeed
COPY nginx.conf /etc/nginx/nginx.conf

If you add a custom CMD in the Dockerfile, be sure to include -g daemon off; in the CMD in order for nginx to stay in the foreground, so that Docker can track the process properly (otherwise your container will stop immediately after starting)!

Then build the image with docker build -t custom-ngxpagespeed . and run it as follows:

$ docker run --name my-custom-ngxpagespeed-container -d custom-ngxpagespeed

Using environment variables in nginx configuration

Out-of-the-box, nginx doesn't support environment variables inside most configuration blocks. But envsubst may be used as a workaround if you need to generate your nginx configuration dynamically before nginx starts.

Here is an example using docker-compose.yml:

web:
  image: pagespeed/nginx-pagespeed
  volumes:
   - ./mysite.template:/etc/nginx/conf.d/mysite.template
  ports:
   - "8080:80"
  environment:
   - NGINX_HOST=foobar.com
   - NGINX_PORT=80
  command: /bin/bash -c "envsubst < /etc/nginx/conf.d/mysite.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"

The mysite.template file may then contain variable references like this:

listen ${NGINX_PORT};

Image Variants

The pagespeed/nginx-pagespeed images come in many flavors, each designed for a specific use case.

pagespeed/nginx-pagespeed:<version>

This is the defacto image. If you are unsure about what your needs are, you probably want to use this one. It is designed to be used both as a throw away container (mount your source code and start the container to start your app), as well as the base to build other images off of.

nginx:edge

This image has the most up-to-date system packages available in the Alpine Linux project. This means the latest LibreSSL and musl-libc, with the downside of having less tested system packages.

Using the Dockerfile

Use docker build command to build an image from dockerfile:

docker build -t <image_tag> <dockerfile_path> . $ docker build -t ngxpagespeed-alpine38-ngxstable stable/3.8/nginx-stable Refer this for additional options.

Run this container as an independent service:

$ docker run -d -p 80:80 <image_tag>

Refer this for additional options.

Requirements for building:

  • 3 GB of free diskspace

  • 2GB of memory
  • an x86_64 compatible processor
  • Docker CE > 17.3.2

Disclaimer

Apache PageSpeed is an effort undergoing incubation at The Apache Software Foundation (ASF), sponsored by the Apache Incubator. Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects. While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF.

License

View PageSpeed license information View Nginx license information

As with all Docker images, these likely also contain other software which may be under other licenses (such as Bash, etc from the base distribution, along with any direct or indirect dependencies of the primary software being contained).

Some additional license information which was able to be auto-detected might be found in the repo-info repository's nginx/ directory.

As for any pre-built image usage, it is the image user's responsibility to ensure that any use of this image complies with any relevant licenses for all software contained within.

Releases

No releases published

Packages

No packages published