├── Dockerfile ├── README.md └── nginx └── nginx.conf /Dockerfile: -------------------------------------------------------------------------------- 1 | ## 2 | # Custom Nginx build with SPDY 2 & mod_pagespeed support 3 | # 4 | # Adapted from https://index.docker.io/u/gvangool/nginx-src/ 5 | # 6 | ## 7 | 8 | FROM ubuntu:precise 9 | MAINTAINER Lauri Svan 10 | 11 | # Set the env variable DEBIAN_FRONTEND to noninteractive 12 | ENV DEBIAN_FRONTEND noninteractive 13 | 14 | # Fix locales 15 | RUN locale-gen en_US.UTF-8 && dpkg-reconfigure locales 16 | 17 | # Enable universe & src repo's 18 | RUN echo "deb http://archive.ubuntu.com/ubuntu precise main restricted universe\ndeb-src http://archive.ubuntu.com/ubuntu precise main restricted universe\ndeb http://archive.ubuntu.com/ubuntu precise-updates main restricted universe\ndeb-src http://archive.ubuntu.com/ubuntu precise-updates main restricted universe\n" > /etc/apt/sources.list 19 | 20 | # Install build tools for nginx 21 | RUN apt-get update && apt-get build-dep nginx-full -y && apt-get install wget -y && apt-get clean && rm -rf /var/lib/apt/lists/* 22 | 23 | # Add Nginx source repository & signing key 24 | #RUN echo "deb http://nginx.org/packages/ubuntu/ precise nginx" >> /etc/apt/sources.list.d/nginx-precise.list 25 | RUN apt-key adv --fetch-keys http://nginx.org/keys/nginx_signing.key 26 | RUN echo "deb-src http://nginx.org/packages/ubuntu/ precise nginx" >> /etc/apt/sources.list.d/nginx-precise.list 27 | 28 | # Add pico; we'll do some local mods anyway 29 | RUN apt-get update && apt-get install nano -y 30 | 31 | # Install Nginx from a tarball 32 | # Install build tools for nginx 33 | ENV NGINX_VERSION 1.4.4 34 | ENV MODULESDIR /usr/src/nginx-modules 35 | RUN cd /usr/src/ && wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz && tar xf nginx-${NGINX_VERSION}.tar.gz && rm -f nginx-${NGINX_VERSION}.tar.gz 36 | 37 | # Force OpenSSL 1.0.1 38 | RUN cd /usr/src && wget http://www.openssl.org/source/openssl-1.0.1e.tar.gz && tar xvzf openssl-1.0.1e.tar.gz 39 | 40 | # Install additional modules 41 | RUN apt-get update && apt-get install -y build-essential zlib1g-dev libpcre3 libpcre3-dev unzip 42 | RUN mkdir ${MODULESDIR} 43 | RUN cd ${MODULESDIR} && \ 44 | wget --no-check-certificate https://github.com/pagespeed/ngx_pagespeed/archive/v1.7.30.3-beta.zip && \ 45 | unzip v1.7.30.3-beta.zip && \ 46 | cd ngx_pagespeed-1.7.30.3-beta/ && \ 47 | wget --no-check-certificate https://dl.google.com/dl/page-speed/psol/1.7.30.3.tar.gz && \ 48 | tar -xzvf 1.7.30.3.tar.gz 49 | 50 | # Compile nginx 51 | RUN cd /usr/src/nginx-${NGINX_VERSION} && ./configure \ 52 | --prefix=/etc/nginx \ 53 | --sbin-path=/usr/sbin/nginx \ 54 | --conf-path=/etc/nginx/nginx.conf \ 55 | --error-log-path=/var/log/nginx/error.log \ 56 | --http-log-path=/var/log/nginx/access.log \ 57 | --pid-path=/var/run/nginx.pid \ 58 | --lock-path=/var/run/nginx.lock \ 59 | --with-http_ssl_module \ 60 | --with-http_realip_module \ 61 | --with-http_addition_module \ 62 | --with-http_sub_module \ 63 | --with-http_dav_module \ 64 | --with-http_flv_module \ 65 | --with-http_mp4_module \ 66 | --with-http_gunzip_module \ 67 | --with-http_gzip_static_module \ 68 | --with-http_random_index_module \ 69 | --with-http_secure_link_module \ 70 | --with-http_stub_status_module \ 71 | --with-mail \ 72 | --with-mail_ssl_module \ 73 | --with-file-aio \ 74 | --with-http_spdy_module \ 75 | --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2' \ 76 | --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,--as-needed' \ 77 | --with-ipv6 \ 78 | --with-sha1=/usr/include/openssl \ 79 | --with-md5=/usr/include/openssl \ 80 | --with-openssl='../openssl-1.0.1e' \ 81 | --add-module=${MODULESDIR}/ngx_pagespeed-1.7.30.3-beta 82 | 83 | RUN cd /usr/src/nginx-${NGINX_VERSION} && make && make install 84 | 85 | ADD nginx /etc/nginx/ 86 | 87 | # Turn off nginx starting as a daemon 88 | RUN echo "daemon off;" >> /etc/nginx/nginx.conf 89 | 90 | # Purge APT cache 91 | RUN apt-get clean all 92 | 93 | EXPOSE 80 443 94 | CMD ["nginx"] 95 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | docker-pagespeed 2 | ================ 3 | 4 | Sample Dockerfile and Nginx configuration to run nginx + ngx_pagespeed. In the 5 | current configuration, nginx acts as a reverse proxy. In future, this will also include 6 | a working SPDY configuration. 7 | 8 | Prior to building, please note that nginx config points to a non-existing site www.sample.com. 9 | Change that with your own setup. 10 | 11 | Build an image with 12 | docker build -t="nginx-pagespeed" -no-cache . 13 | 14 | And start it with 15 | docker run -p 59080:80 -i -t nginx-pagespeed 16 | 17 | For debugging & playing with nginx config on the image, do 18 | docker run -p 59080:80 -i -t nginx-defer /bin/bash 19 | -------------------------------------------------------------------------------- /nginx/nginx.conf: -------------------------------------------------------------------------------- 1 | # Sample configuration for using mod_pagespeed 2 | # Change references to www.sample.com and www.sample.com/path to your host and its mapped path(s). 3 | 4 | # Run as root to avoid mod_pagespeed permission problems 5 | # TODO Running as nginx user of its own 6 | user root root; 7 | 8 | events { 9 | worker_connections 1024; 10 | } 11 | 12 | http { 13 | include mime.types; 14 | default_type application/octet-stream; 15 | 16 | sendfile on; 17 | keepalive_timeout 65; 18 | 19 | gzip on; 20 | 21 | server { 22 | listen 80; 23 | server_name localhost; 24 | 25 | # Enable pagespeed 26 | pagespeed on; 27 | 28 | # Needs to exist and be writable by nginx. 29 | pagespeed FileCachePath /var/ngx_pagespeed_cache; 30 | 31 | # Ensure requests for pagespeed optimized resources go to the pagespeed handler 32 | # and no extraneous headers get set. 33 | location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" { 34 | add_header "" ""; 35 | } 36 | location ~ "^/ngx_pagespeed_static/" { } 37 | location ~ "^/ngx_pagespeed_beacon$" { } 38 | location /ngx_pagespeed_statistics { allow 127.0.0.1; deny all; } 39 | location /ngx_pagespeed_global_statistics { allow 127.0.0.1; deny all; } 40 | location /ngx_pagespeed_message { allow 127.0.0.1; deny all; } 41 | 42 | # The filters we'll use 43 | pagespeed EnableFilters rewrite_domains,trim_urls,rewrite_css,sprite_images,prioritize_critical_css,lazyload_images,defer_javascript; 44 | 45 | # The target subject 46 | pagespeed Domain www.sample.com; 47 | 48 | # TODO Get rid of the port (caused by docker config) 49 | pagespeed MapProxyDomain localhost:59080/path www.sample.com/path; 50 | 51 | # Force caching to get the css into pagespeed cache 52 | pagespeed ForceCaching on; 53 | 54 | location / { 55 | proxy_pass http://www.sample.com/; 56 | } 57 | } 58 | } 59 | --------------------------------------------------------------------------------