├── Dockerfile ├── _build.bat ├── _push.bat ├── _test.bat ├── entrypoint.sh ├── examples └── 01-docker.com │ ├── 01-docker.com-result.png │ ├── 01-docker.com.htm │ ├── 01-docker.com.png │ └── nginx.conf ├── nginx-upstart.conf ├── readme.md └── setup-02-compile.sh /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:17.04 2 | MAINTAINER Luiz Carlos Faria 3 | WORKDIR /home 4 | 5 | # Set the env variable DEBIAN_FRONTEND to noninteractive 6 | ENV DEBIAN_FRONTEND noninteractive 7 | 8 | RUN apt-get update && \ 9 | apt-get install wget curl nano build-essential zlib1g-dev libpcre3 libpcre3-dev libssl-dev libxslt1-dev libxml2-dev zip unzip libgd2-xpm-dev libgeoip-dev libgoogle-perftools-dev libperl-dev git -y 10 | 11 | # Fix locales 12 | RUN apt-get update && apt-get install -y locales && rm -rf /var/lib/apt/lists/* \ 13 | && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 14 | ENV LANG en_US.utf8 15 | 16 | ENV NGINX_VERSION 1.12.0 17 | ENV NPS_VERSION 1.11.33.4 18 | ENV RTMP_VERSION 1.1.11 19 | 20 | RUN pwd && ls -l && echo 1 21 | # Configure 22 | 23 | COPY ./setup-02-compile.sh ./setup-02-compile.sh 24 | RUN chmod +x ./setup-02-compile.sh \ 25 | && ls -l \ 26 | && ./setup-02-compile.sh 27 | 28 | 29 | EXPOSE 80 30 | EXPOSE 443 31 | 32 | COPY ./nginx-upstart.conf /etc/init/nginx.conf 33 | COPY ./entrypoint.sh /entrypoint.sh 34 | RUN chmod +x /entrypoint.sh \ 35 | && apt-get clean all \ 36 | && mkdir /_config_backup/ \ 37 | && cp /etc/nginx/* /_config_backup/ 38 | 39 | RUN mkdir /var/ngx_pagespeed_cache/ \ 40 | && chmod 777 /var/ngx_pagespeed_cache/ 41 | 42 | RUN mkdir /var/ngx_pagespeed_log/ \ 43 | && chmod 777 /var/ngx_pagespeed_log/ 44 | 45 | WORKDIR / 46 | 47 | VOLUME ["/etc/nginx/", "/var/log/nginx/"] 48 | 49 | ENTRYPOINT ["/entrypoint.sh"] 50 | 51 | CMD ["nginx", "-g", "daemon off;"] -------------------------------------------------------------------------------- /_build.bat: -------------------------------------------------------------------------------- 1 | docker build -t luizcarlosfaria/nginx-pagespeed:latest . -------------------------------------------------------------------------------- /_push.bat: -------------------------------------------------------------------------------- 1 | docker tag luizcarlosfaria/nginx-pagespeed:latest luizcarlosfaria/nginx-pagespeed:nginx-1.12.0--pagespeed-1.11.33.4--RTMP-1.1.11 2 | docker push luizcarlosfaria/nginx-pagespeed:latest 3 | docker push luizcarlosfaria/nginx-pagespeed:nginx-1.12.0--pagespeed-1.11.33.4--RTMP-1.1.11 -------------------------------------------------------------------------------- /_test.bat: -------------------------------------------------------------------------------- 1 | docker rm -f customNginx 2 | docker run --name customNginx -d --hostname customNginx -p 80:80 -v %~dp0examples\01-docker.com\nginx.conf:/etc/nginx/nginx.conf -v %~dp0examples\01-docker.com\logs:/var/log/nginx/ luizcarlosfaria/nginx-pagespeed 3 | 4 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | if [ ! -f /etc/nginx/nginx.conf ]; then 5 | cp /_config_backup/. /etc/nginx -R 6 | fi 7 | 8 | exec "$@" 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /examples/01-docker.com/01-docker.com-result.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luizcarlosfaria/nginx-pagespeed/000e513815d3a3e37b147bd94d9fbab5297b4f40/examples/01-docker.com/01-docker.com-result.png -------------------------------------------------------------------------------- /examples/01-docker.com/01-docker.com.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luizcarlosfaria/nginx-pagespeed/000e513815d3a3e37b147bd94d9fbab5297b4f40/examples/01-docker.com/01-docker.com.png -------------------------------------------------------------------------------- /examples/01-docker.com/nginx.conf: -------------------------------------------------------------------------------- 1 | #user nobody; 2 | worker_processes 5; 3 | 4 | #error_log logs/error.log; 5 | #error_log logs/error.log notice; 6 | #error_log logs/error.log info; 7 | 8 | #pid logs/nginx.pid; 9 | 10 | 11 | events { 12 | worker_connections 1024; 13 | } 14 | 15 | 16 | http { 17 | include mime.types; 18 | default_type application/octet-stream; 19 | 20 | #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 21 | # '$status $body_bytes_sent "$http_referer" ' 22 | # '"$http_user_agent" "$http_x_forwarded_for"'; 23 | 24 | #access_log logs/access.log main; 25 | 26 | sendfile on; 27 | #tcp_nopush on; 28 | 29 | #keepalive_timeout 0; 30 | keepalive_timeout 65; 31 | 32 | gzip on; 33 | pagespeed GlobalStatisticsPath /ngx_pagespeed_global_statistics; 34 | pagespeed GlobalAdminPath /pagespeed_global_admin; 35 | pagespeed RewriteLevel OptimizeForBandwidth; 36 | pagespeed ForceCaching on; 37 | pagespeed StatisticsLoggingIntervalMs 60000; 38 | pagespeed StatisticsLoggingMaxFileSizeKb 1024; 39 | 40 | server { 41 | listen 80; 42 | server_name localhost; 43 | #################################################################################################### 44 | pagespeed on; 45 | # Needs to exist and be writable by nginx. Use tmpfs for best performance. 46 | pagespeed FileCachePath /var/ngx_pagespeed_cache/; 47 | pagespeed MessagesPath /ngx_pagespeed_message; 48 | pagespeed ConsolePath /pagespeed_console; 49 | pagespeed AdminPath /pagespeed_admin; 50 | 51 | pagespeed Statistics on; 52 | pagespeed StatisticsLogging on; 53 | pagespeed StatisticsPath /pagespeed_statistics; 54 | pagespeed LogDir /var/ngx_pagespeed_log; 55 | 56 | # Ensure requests for pagespeed optimized resources go to the pagespeed handler 57 | # and no extraneous headers get set. 58 | location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" { 59 | add_header "" ""; 60 | } 61 | location ~ "^/pagespeed_static/" { } 62 | location ~ "^/ngx_pagespeed_beacon$" { } 63 | 64 | #################################################################################################### 65 | #location /ngx_pagespeed_statistics { allow all; } 66 | #location /ngx_pagespeed_global_statistics { allow all; } 67 | #location /ngx_pagespeed_message { allow all; } 68 | #location /pagespeed_console { allow all; } 69 | #location ~ ^/pagespeed_admin { allow all; } 70 | #location ~ ^/pagespeed_global_admin { allow all; } 71 | #################################################################################################### 72 | 73 | #charset koi8-r; 74 | 75 | #access_log logs/host.access.log main; 76 | 77 | #location / { 78 | # root html; 79 | # index index.html index.htm; 80 | #} 81 | 82 | location / { 83 | 84 | 85 | 86 | 87 | proxy_pass http://www.correios.com.br; 88 | proxy_set_header Host www.correios.com.br; 89 | #proxy_set_header X-Real-IP $remote_addr; 90 | proxy_set_header Accept-Encoding "deflate, sdch, br"; 91 | 92 | subs_filter_types text/css text/xml application/javascript text/javascript; 93 | subs_filter www.correios.com.br localhost; 94 | 95 | pagespeed RewriteLevel PassThrough; 96 | pagespeed EnableFilters combine_css,extend_cache,rewrite_images; 97 | pagespeed EnableFilters rewrite_css,rewrite_javascript; 98 | pagespeed MaxCombinedCssBytes 9999999999; 99 | pagespeed MaxCombinedJsBytes 9999999999; 100 | pagespeed MaxSegmentLength 1024; 101 | pagespeed CombineAcrossPaths on; 102 | #pagespeed RewriteLevel CoreFilters; 103 | #pagespeed InPlaceResourceOptimization on; 104 | } 105 | 106 | 107 | } 108 | 109 | 110 | 111 | } -------------------------------------------------------------------------------- /nginx-upstart.conf: -------------------------------------------------------------------------------- 1 | # nginx 2 | 3 | description "nginx http daemon" 4 | 5 | start on (filesystem and net-device-up IFACE=lo) 6 | stop on runlevel [!2345] 7 | 8 | env DAEMON=/usr/local/sbin/nginx 9 | env PID=/run/nginx.pid 10 | 11 | expect fork 12 | respawn 13 | respawn limit 10 5 14 | #oom never 15 | 16 | pre-start script 17 | $DAEMON -t 18 | if [ $? -ne 0 ] 19 | then exit $? 20 | fi 21 | end script 22 | 23 | exec $DAEMON 24 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Supported tags and respective ```Dockerfile``` links 2 | 3 | * [```nginx-1.11.4--pagespeed-1.12.0--RTMP-1.1.11```](https://github.com/docker-gallery/nginx-pagespeed/tree/nginx-1.12.0--pagespeed-1.11.33.4--RTMP-1.1.11), ```latest``` 4 | * [```nginx-1.11.4--pagespeed-1.11.33.3--RTMP-1.1.9```](https://github.com/docker-gallery/nginx-pagespeed/tree/nginx-1.11.4--pagespeed-1.11.33.3--RTMP-1.1.9), ```latest``` 5 | * [```nginx-1.10.1--pagespeed-1.11.33.3```](https://github.com/docker-gallery/nginx-pagespeed/tree/nginx-1.10.1--pagespeed-1.11.33.3) 6 | 7 | ## Include 8 | This image contains Nginx built with some modules: 9 | * Nginx 1.12.0 10 | * ngx_http_substitutions_filter_module 11 | * Google Page Speed 1.11.33.4 12 | * nginx-rtmp-module 1.1.11 13 | 14 | ## How to use this image 15 | 16 | ``` 17 | docker run --name customNginx -d --hostname customNginx -p 80:80 -v /some/config:/etc/nginx/ -v /some/logs:/var/log/nginx/ luizcarlosfaria/nginx-pagespeed 18 | ``` 19 | 20 | ## Volumes 21 | * "/etc/nginx/" - Configuration files 22 | * "/var/log/nginx/" - Logs 23 | 24 | ## Build paths and variables 25 | Nginx has built with those variables and paths: 26 | ``` 27 | # nginx path prefix: "/usr/local/nginx" 28 | # nginx binary file: "/usr/local/sbin/nginx" 29 | # nginx configuration prefix: "/etc/nginx" 30 | # nginx configuration file: "/etc/nginx/nginx.conf" 31 | # nginx pid file: "/run/nginx.pid" 32 | # nginx error log file: "/var/log/nginx/error.log" 33 | # nginx http access log file: "/var/log/nginx/access.log" 34 | # nginx http client request body temporary files: "client_body_temp" 35 | # nginx http proxy temporary files: "proxy_temp" 36 | # nginx http fastcgi temporary files: "fastcgi_temp" 37 | # nginx http uwsgi temporary files: "uwsgi_temp" 38 | # nginx http scgi temporary files: "scgi_temp" 39 | ``` 40 | 41 | ## Based on [ubuntu:17.04](https://hub.docker.com/_/ubuntu/) image 42 | This image is based on Ubuntu:17.04 official image. 43 | 44 | ## Full featured NGINX configuration using Google Page Speed 45 | This is an example Nginx configuration file, you can placed it on ```/some/config/nginx.conf``` on your host OR ```/etc/nginx/nginx.conf``` on container. 46 | This example use a virtualpath /v2/ as proxy. 47 | 48 | See morre on [PageSpeed Tools](https://developers.google.com/speed/pagespeed/module/filter-head-add) docs, 49 | [nginx-rtmp-module](https://github.com/arut/nginx-rtmp-module) docs and 50 | [ngx_http_substitutions_filter_module](https://github.com/yaoweibin/ngx_http_substitutions_filter_module) docs. 51 | 52 | ``` 53 | #user nobody; 54 | worker_processes 1; 55 | 56 | #error_log logs/error.log; 57 | #error_log logs/error.log notice; 58 | #error_log logs/error.log info; 59 | 60 | #pid logs/nginx.pid; 61 | 62 | 63 | events { 64 | worker_connections 1024; 65 | } 66 | 67 | 68 | http { 69 | include mime.types; 70 | default_type application/octet-stream; 71 | 72 | #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 73 | # '$status $body_bytes_sent "$http_referer" ' 74 | # '"$http_user_agent" "$http_x_forwarded_for"'; 75 | 76 | #access_log logs/access.log main; 77 | 78 | sendfile on; 79 | #tcp_nopush on; 80 | 81 | #keepalive_timeout 0; 82 | keepalive_timeout 65; 83 | 84 | #gzip on; 85 | pagespeed GlobalStatisticsPath /ngx_pagespeed_global_statistics; 86 | pagespeed GlobalAdminPath /pagespeed_global_admin; 87 | 88 | server { 89 | listen 80; 90 | server_name localhost; 91 | #################################################################################################### 92 | pagespeed on; 93 | # Needs to exist and be writable by nginx. Use tmpfs for best performance. 94 | pagespeed FileCachePath /var/ngx_pagespeed_cache/; 95 | pagespeed MessagesPath /ngx_pagespeed_message; 96 | pagespeed ConsolePath /pagespeed_console; 97 | pagespeed AdminPath /pagespeed_admin; 98 | 99 | pagespeed StatisticsPath /pagespeed_statistics; 100 | 101 | # Ensure requests for pagespeed optimized resources go to the pagespeed handler 102 | # and no extraneous headers get set. 103 | location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" { 104 | add_header "" ""; 105 | } 106 | location ~ "^/pagespeed_static/" { } 107 | location ~ "^/ngx_pagespeed_beacon$" { } 108 | 109 | #################################################################################################### 110 | #location /ngx_pagespeed_statistics { allow all; } 111 | #location /ngx_pagespeed_global_statistics { allow all; } 112 | #location /ngx_pagespeed_message { allow all; } 113 | #location /pagespeed_console { allow all; } 114 | #location ~ ^/pagespeed_admin { allow all; } 115 | #location ~ ^/pagespeed_global_admin { allow all; } 116 | #################################################################################################### 117 | 118 | #charset koi8-r; 119 | 120 | #access_log logs/host.access.log main; 121 | 122 | location / { 123 | root html; 124 | index index.html index.htm; 125 | } 126 | 127 | location /v2/ { 128 | 129 | pagespeed EnableFilters move_css_to_head; 130 | pagespeed EnableFilters combine_javascript; 131 | pagespeed MaxCombinedJsBytes 999999999; 132 | pagespeed CombineAcrossPaths on; 133 | pagespeed MaxSegmentLength 2048; 134 | pagespeed EnableFilters responsive_images,resize_images; 135 | pagespeed EnableFilters responsive_images_zoom; 136 | pagespeed EnableFilters collapse_whitespace; 137 | 138 | proxy_pass http://my-remove-app-to-test:80/v2/; 139 | proxy_set_header X-Real-IP $remote_addr; 140 | } 141 | 142 | 143 | } 144 | 145 | 146 | 147 | } 148 | 149 | ``` 150 | -------------------------------------------------------------------------------- /setup-02-compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | mkdir /home/build 5 | cd /home/build/ 6 | echo '###############################################################################################' && pwd && ls -l && echo '###############################################################################################' 7 | # Download ngx_http_substitutions_filter_module 8 | git clone git://github.com/yaoweibin/ngx_http_substitutions_filter_module.git 9 | echo '###############################################################################################' && pwd && ls -l && echo '###############################################################################################' 10 | #Dowload do nginx-rtmp-module 11 | wget "https://github.com/arut/nginx-rtmp-module/archive/v${RTMP_VERSION}.tar.gz" \ 12 | && tar -xzvf v${RTMP_VERSION}.tar.gz # extracts RTM/ 13 | echo '###############################################################################################' && pwd && ls -l && echo '###############################################################################################' 14 | # Download Google Page Speed 15 | echo '###############################################################################################' && pwd && ls -l && echo '###############################################################################################' 16 | wget https://github.com/pagespeed/ngx_pagespeed/archive/v${NPS_VERSION}-beta.zip -O nginx-${NPS_VERSION}-beta.zip 17 | unzip nginx-${NPS_VERSION}-beta.zip 18 | cd /home/build/ngx_pagespeed-${NPS_VERSION}-beta/ 19 | echo '###############################################################################################' && pwd && ls -l && echo '###############################################################################################' 20 | wget https://dl.google.com/dl/page-speed/psol/${NPS_VERSION}.tar.gz \ 21 | && tar -xzvf ${NPS_VERSION}.tar.gz # extracts to psol/ 22 | echo '###############################################################################################' && pwd && ls -l && echo '###############################################################################################' 23 | 24 | 25 | # Download Nginx 26 | cd /home/build/ 27 | wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz 28 | tar -zxvf nginx-${NGINX_VERSION}.tar.gz 29 | cd /home/build/nginx-${NGINX_VERSION} 30 | echo '###############################################################################################' && pwd && ls -l && echo '###############################################################################################' 31 | 32 | ./configure \ 33 | --prefix=/usr/local/nginx \ 34 | --sbin-path=/usr/local/sbin/nginx \ 35 | --conf-path=/etc/nginx/nginx.conf \ 36 | --error-log-path=/var/log/nginx/error.log \ 37 | --http-log-path=/var/log/nginx/access.log \ 38 | --pid-path=/run/nginx.pid \ 39 | --lock-path=/run/lock/subsys/nginx \ 40 | --user=nginx \ 41 | --group=nginx \ 42 | --with-file-aio \ 43 | --with-ipv6 \ 44 | --with-http_ssl_module \ 45 | --with-http_v2_module \ 46 | --with-http_realip_module \ 47 | --with-http_addition_module \ 48 | --with-http_xslt_module \ 49 | --with-stream \ 50 | --with-http_image_filter_module \ 51 | --with-http_geoip_module \ 52 | --with-http_sub_module \ 53 | --with-http_dav_module \ 54 | --with-http_flv_module \ 55 | --with-http_mp4_module \ 56 | --with-http_gunzip_module \ 57 | --with-http_gzip_static_module \ 58 | --with-http_random_index_module \ 59 | --with-http_secure_link_module \ 60 | --with-http_degradation_module \ 61 | --with-http_stub_status_module \ 62 | --with-http_perl_module \ 63 | --with-mail \ 64 | --with-mail_ssl_module \ 65 | --with-pcre \ 66 | --with-google_perftools_module \ 67 | --add-module=../ngx_http_substitutions_filter_module \ 68 | --add-module=../ngx_pagespeed-${NPS_VERSION}-beta \ 69 | --add-module=../nginx-rtmp-module-${RTMP_VERSION} 70 | 71 | # --with-debug 72 | #Configuration summary 73 | # + using system PCRE library 74 | # + using system OpenSSL library 75 | # + md5: using OpenSSL library 76 | # + sha1: using OpenSSL library 77 | # + using system zlib library 78 | 79 | # nginx path prefix: "/usr/local/nginx" 80 | # nginx binary file: "/usr/local/sbin/nginx" 81 | # nginx configuration prefix: "/etc/nginx" 82 | # nginx configuration file: "/etc/nginx/nginx.conf" 83 | # nginx pid file: "/run/nginx.pid" 84 | # nginx error log file: "/var/log/nginx/error.log" 85 | # nginx http access log file: "/var/log/nginx/access.log" 86 | # nginx http client request body temporary files: "client_body_temp" 87 | # nginx http proxy temporary files: "proxy_temp" 88 | # nginx http fastcgi temporary files: "fastcgi_temp" 89 | # nginx http uwsgi temporary files: "uwsgi_temp" 90 | # nginx http scgi temporary files: "scgi_temp" 91 | 92 | 93 | 94 | make 95 | make install 96 | useradd -r nginx 97 | 98 | 99 | apt-get clean \ 100 | && apt-get autoremove -y \ 101 | && rm -rf /var/lib/apt/lists/* \ 102 | && rm -rf /home/build/* 103 | 104 | --------------------------------------------------------------------------------