├── .dockerignore ├── .env-example ├── .gitignore ├── Dockerfile ├── README.md ├── cloudbuild.yaml ├── config ├── conf.d │ ├── core.conf │ ├── default.conf │ ├── geoip2.conf │ ├── gzip.conf │ ├── pagespeed-css.conf │ ├── pagespeed-image.conf │ ├── pagespeed-js.conf │ ├── pagespeed.conf │ └── status.conf ├── fastcgi_params.orig ├── include │ ├── fastcgi_params │ ├── pagespeed.conf │ ├── rewrite-index.conf │ ├── rewrite-w3tc.conf │ └── rewrite-wp.conf └── nginx.conf ├── docker-compose.yml ├── env-example ├── geoip2 └── .gitkeep └── scripts ├── docker-entrypoint.sh └── initialize.sh /.dockerignore: -------------------------------------------------------------------------------- 1 | .env 2 | -------------------------------------------------------------------------------- /.env-example: -------------------------------------------------------------------------------- 1 | ### add path to include extra configuration files : (default: off) 2 | NGINX_INCLUDE_PATH=/app/config/nginx/*.conf 3 | 4 | ### Include default server definition with health check: on|off (default: on) 5 | ### Nginx will not be able to start without default server configured with /healthcheck 6 | NGINX_DEFAULT_SERVER=on 7 | 8 | ### Include extra common fastcgi PHP GeoIP variables: on|off (default: on) 9 | NGINX_FASTCGI_GEOIP=on 10 | 11 | ### Google PageSpeed algorithm: on|off (default: off) 12 | NGINX_PAGESPEED=on 13 | 14 | ### PageSpeed image optimization: on|off (default: off) 15 | NGINX_PAGESPEED_IMG=on 16 | 17 | ### PageSpeed javascripts optimization: on|off (default: off) 18 | NGINX_PAGESPEED_JS=on 19 | 20 | ### PageSpeed style sheets optimization: on|off (default: off) 21 | NGINX_PAGESPEED_CSS=on 22 | 23 | ### PageSpeed cache storage: files|redis|memcached (default: files) 24 | NGINX_PAGESPEED_STORAGE=files 25 | 26 | ### PageSpeed Redis cache storage address and port: redis.host:port (default: none) 27 | NGINX_PAGESPEED_REDIS=redis.host:6379 28 | 29 | ### PageSpeed Memcached cache storage address and port: memcached.host:port (default: none) 30 | NGINX_PAGESPEED_MEMCACHED=memcached.host:11211 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | geoip/ 3 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:buster-slim 2 | 3 | ARG MAKE_J=4 4 | ARG NGINX_VERSION=1.19.7 5 | ARG PAGESPEED_VERSION=1.13.35.2 6 | ARG LIBPNG_VERSION=1.6.37 7 | 8 | ENV MAKE_J=${MAKE_J} \ 9 | NGINX_VERSION=${NGINX_VERSION} \ 10 | LIBPNG_VERSION=${LIBPNG_VERSION} \ 11 | PAGESPEED_VERSION=${PAGESPEED_VERSION} 12 | 13 | RUN apt-get update -y && \ 14 | apt-get upgrade -y 15 | 16 | RUN apt-get install -y \ 17 | apt-utils \ 18 | git nano \ 19 | g++ \ 20 | gcc \ 21 | curl \ 22 | make \ 23 | unzip \ 24 | bzip2 \ 25 | gperf \ 26 | python \ 27 | openssl \ 28 | libuuid1 \ 29 | apt-utils \ 30 | pkg-config \ 31 | icu-devtools \ 32 | build-essential \ 33 | ca-certificates \ 34 | uuid-dev \ 35 | zlib1g-dev \ 36 | libicu-dev \ 37 | libssl-dev \ 38 | apache2-dev \ 39 | libpcre3 \ 40 | libpcre3-dev \ 41 | libmaxminddb-dev \ 42 | libpng-dev \ 43 | libaprutil1-dev \ 44 | linux-headers-amd64 \ 45 | libjpeg62-turbo-dev \ 46 | libcurl4-openssl-dev 47 | 48 | # Build libpng 49 | RUN cd /tmp && \ 50 | curl -L http://prdownloads.sourceforge.net/libpng/libpng-${LIBPNG_VERSION}.tar.gz | tar -zx && \ 51 | cd /tmp/libpng-${LIBPNG_VERSION} && \ 52 | ./configure --build=$CBUILD --host=$CHOST --prefix=/usr --enable-shared --with-libpng-compat && \ 53 | make -j${MAKE_J} install V=0 54 | 55 | RUN cd /tmp && \ 56 | curl -O -L https://github.com/pagespeed/ngx_pagespeed/archive/v${PAGESPEED_VERSION}-stable.zip && \ 57 | unzip v${PAGESPEED_VERSION}-stable.zip 58 | 59 | RUN cd /tmp/incubator-pagespeed-ngx-${PAGESPEED_VERSION}-stable/ && \ 60 | psol_url=https://dl.google.com/dl/page-speed/psol/${PAGESPEED_VERSION}.tar.gz && \ 61 | [ -e scripts/format_binary_url.sh ] && psol_url=$(scripts/format_binary_url.sh PSOL_BINARY_URL) && \ 62 | echo "URL: ${psol_url}" && \ 63 | curl -L ${psol_url} | tar -xz 64 | 65 | # Build in additional Nginx modules 66 | RUN cd /tmp && \ 67 | git clone git://github.com/vozlt/nginx-module-vts.git && \ 68 | git clone https://github.com/FRiCKLE/ngx_cache_purge.git && \ 69 | git clone https://github.com/simplresty/ngx_devel_kit.git && \ 70 | git clone https://github.com/leev/ngx_http_geoip2_module.git && \ 71 | git clone https://github.com/openresty/echo-nginx-module.git && \ 72 | git clone https://github.com/onnimonni/redis-nginx-module.git && \ 73 | git clone https://github.com/openresty/redis2-nginx-module.git && \ 74 | git clone https://github.com/openresty/srcache-nginx-module.git && \ 75 | git clone https://github.com/openresty/set-misc-nginx-module.git && \ 76 | git clone https://github.com/openresty/headers-more-nginx-module.git && \ 77 | git clone git://github.com/yaoweibin/ngx_http_substitutions_filter_module.git 78 | 79 | RUN ls -la /tmp/ 80 | RUN ls -la /tmp/ngx_http_geoip2_module 81 | 82 | # Build Nginx with support for PageSpeed 83 | RUN cd /tmp && \ 84 | curl -L http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz | tar -zx && \ 85 | cd /tmp/nginx-${NGINX_VERSION} && \ 86 | LD_LIBRARY_PATH=/tmp/incubator-pagespeed-ngx-${PAGESPEED_VERSION}/usr/lib:/usr/lib ./configure \ 87 | --sbin-path=/usr/sbin \ 88 | --modules-path=/usr/lib/nginx \ 89 | --with-http_ssl_module \ 90 | --with-http_gzip_static_module \ 91 | --with-file-aio \ 92 | --with-http_v2_module \ 93 | --with-http_realip_module \ 94 | --with-http_sub_module \ 95 | --with-http_gunzip_module \ 96 | --with-http_secure_link_module \ 97 | --with-http_stub_status_module \ 98 | --with-threads \ 99 | --with-stream \ 100 | --with-stream_ssl_module \ 101 | --without-http_autoindex_module \ 102 | --without-http_browser_module \ 103 | --without-http_userid_module \ 104 | --without-mail_pop3_module \ 105 | --without-mail_imap_module \ 106 | --without-mail_smtp_module \ 107 | --without-http_split_clients_module \ 108 | --without-http_uwsgi_module \ 109 | --without-http_scgi_module \ 110 | --without-http_upstream_ip_hash_module \ 111 | --prefix=/etc/nginx \ 112 | --conf-path=/etc/nginx/nginx.conf \ 113 | --http-log-path=/var/log/nginx/access.log \ 114 | --error-log-path=/var/log/nginx/error.log \ 115 | --pid-path=/var/run/nginx.pid \ 116 | --add-module=/tmp/ngx_devel_kit \ 117 | --add-module=/tmp/ngx_cache_purge \ 118 | --add-module=/tmp/nginx-module-vts \ 119 | --add-module=/tmp/echo-nginx-module \ 120 | --add-module=/tmp/redis-nginx-module \ 121 | --add-module=/tmp/redis2-nginx-module \ 122 | --add-module=/tmp/srcache-nginx-module \ 123 | --add-module=/tmp/set-misc-nginx-module \ 124 | --add-module=/tmp/ngx_http_geoip2_module \ 125 | --add-module=/tmp/headers-more-nginx-module \ 126 | --add-module=/tmp/ngx_http_substitutions_filter_module \ 127 | --add-module=/tmp/incubator-pagespeed-ngx-${PAGESPEED_VERSION}-stable && \ 128 | make install --silent 129 | 130 | # Clean-up 131 | RUN apt-get remove -y git 132 | RUN rm -rf /var/lib/apt/lists/* && rm -rf /tmp/* && \ 133 | # Forward request and error logs to docker log collector 134 | ln -sf /dev/stdout /var/log/nginx/access.log && \ 135 | ln -sf /dev/stderr /var/log/nginx/error.log && \ 136 | # Make PageSpeed cache writable 137 | mkdir -p /var/cache/ngx_pagespeed && \ 138 | chmod -R o+wr /var/cache/ngx_pagespeed 139 | 140 | ### MaxMind not longer supports database downloads 141 | ### so upload them yourself into /usr/share/GeoIP2 folder 142 | RUN mkdir -p /usr/share/GeoIP2 143 | ADD ./geoip2/* /usr/share/GeoIP2/ 144 | 145 | ### MaxMind Deprecated GeoIP2 databases download URLs 146 | # RUN cd /usr/share/GeoIP2 && \ 147 | # curl -L -O https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz && \ 148 | # curl -L -O https://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.mmdb.gz && \ 149 | # gzip -d * 150 | 151 | # Inject Nginx configuration files 152 | COPY ./config/conf.d /etc/nginx/conf.d 153 | COPY ./config/include /etc/nginx/include 154 | COPY ./config/nginx.conf /etc/nginx/nginx.conf 155 | COPY ./config/fastcgi_params.orig /etc/nginx/fastcgi_params.orig 156 | COPY ./scripts /usr/local/bin/ 157 | 158 | RUN chmod +x /usr/local/bin/* 159 | 160 | EXPOSE 80 8080 161 | WORKDIR /etc/nginx 162 | 163 | HEALTHCHECK --interval=5s --timeout=5s CMD curl -I http://127.0.0.1:8080/health || exit 1 164 | 165 | ENTRYPOINT ["docker-entrypoint.sh"] 166 | CMD ["nginx", "-g", "daemon off;"] 167 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Docker Nginx + PageSpeed + GEO IP 2 | 3 | This docker image based on Debian Stretch linux distribution. 4 | Project goal is an easy to build docker image of latest Nginx web server with Google PageSpeed and Geo IP modules. 5 | 6 | ## PageSpeed 7 | 8 | The [PageSpeed](https://developers.google.com/speed/pagespeed/) tools analyze and optimize your site following web best practices. If turned ON it exposes a PageSpeed admin status page at: 9 | 10 | - `http://localhost:8080/pagespeed_admin/` 11 | 12 | ## VTS 13 | 14 | The [VTS](https://github.com/vozlt/nginx-module-vts) Nginx virtual host traffic status module. It exposes a status page at: 15 | 16 | - `http://localhost:8080/status/` 17 | 18 | ## GeoIP 19 | 20 | The [GeoIP](https://www.maxmind.com/en/geoip-demo) databases to help decode remote IP address into geographical location. 21 | 22 | **Important**: Due to data privacy regulations, [MaxMind made changes](https://dev.maxmind.com/geoip/geoip2/geolite2/) to how you can access free GeoLite2 databases. Since database files cannot be accessed by a public URL, you will have to download them manually. 23 | 24 | ## More Headers 25 | 26 | The [more_set_headers](https://github.com/openresty/headers-more-nginx-module)allows to set more HTTP response headers - useful in multi cluster environments. 27 | 28 | ## Substitutions Filter 29 | 30 | The [subs_filter](https://github.com/yaoweibin/ngx_http_substitutions_filter_module) allows nginx to filter which can do both regular expression and fixed string substitutions on response bodies. 31 | 32 | ## Json access log 33 | 34 | Container will produce web server access log through docker /stdout in json format for easy parsing via 3rd party containers like Fluentd. 35 | 36 | ### Main features 37 | 38 | Include environment variables to turn ON | OFF Page Speed optimization features for: 39 | 40 | - images 41 | - javascripts 42 | - style sheets 43 | - cache engine for cluster environments: files, memcached or redis 44 | 45 | as well as: 46 | 47 | - vhosts stats page 48 | - default host with health check 49 | - [FastCGI file cache](https://www.nginx.com/blog/9-tips-for-improving-wordpress-performance-with-nginx/) 50 | - [Redis memory cache](https://easyengine.io/wordpress-nginx/tutorials/single-site/redis_cache-with-conditional-purging/) 51 | 52 | Nginx is configured by default for high performance, multi cluster production environment, but can be easily adjusted with environment variables. 53 | 54 | ### Configuration 55 | 56 | Example docker-compose.yml uses default environment variables: 57 | 58 | ```env 59 | MAKE_J=4 60 | NGINX_VERSION=1.13.3 61 | PAGESPEED_VERSION=1.12.34.2 62 | LIBPNG_VERSION=1.6.29 63 | 64 | ### add path to include extra configuration files : (default: off) 65 | NGINX_INCLUDE_PATH=/app/config/nginx/*.conf 66 | 67 | ### Include default server definition with health check: on|off (default: on) 68 | NGINX_DEFAULT_SERVER=on 69 | 70 | ### Configure GeoIP support and include extra common fastcgi PHP GeoIP variables: on|off (default: off) 71 | ### Deprecated: `NGINX_FASTCGI_GEOIP` variable 72 | NGINX_GEOIP=on 73 | 74 | ### Google PageSpeed algorithm: on|off (default: off) 75 | NGINX_PAGESPEED=on 76 | 77 | ### PageSpeed image optimization: on|off (default: off) 78 | NGINX_PAGESPEED_IMG=on 79 | 80 | ### PageSpeed javascripts optimization: on|off (default: off) 81 | NGINX_PAGESPEED_JS=on 82 | 83 | ### PageSpeed style sheets optimization: on|off (default: off) 84 | NGINX_PAGESPEED_CSS=on 85 | 86 | ### PageSpeed cache storage: files|redis|memcached (default: files) 87 | NGINX_PAGESPEED_STORAGE=files 88 | 89 | ### PageSpeed Redis cache storage address and port: redis.host:port (default: none) 90 | NGINX_PAGESPEED_REDIS=redis.host:6379 91 | 92 | ### PageSpeed Memcached cache storage address and port: memcached.host:port (default: none) 93 | NGINX_PAGESPEED_MEMCACHED=memcached.host:11211 94 | ``` 95 | -------------------------------------------------------------------------------- /cloudbuild.yaml: -------------------------------------------------------------------------------- 1 | steps: 2 | # slack deployment status 3 | - name: 'gcr.io/cloud-builders/curl' 4 | args: [ '-X', 'POST', '-H', 'Content-type: application/json', '--data', 5 | '{"text":"`gcr.io/$PROJECT_ID/$_IMAGE:$BRANCH_NAME$TAG_NAME` build started!"}', '${_WEBHOOK_URL}' ] 6 | 7 | # pull docker image for cache 8 | - name: 'gcr.io/cloud-builders/docker' 9 | entrypoint: 'bash' 10 | args: 11 | - '-c' 12 | - | 13 | docker pull gcr.io/$PROJECT_ID/$_IMAGE:$BRANCH_NAME || exit 0 14 | 15 | # build docker image 16 | - name: 'gcr.io/cloud-builders/docker' 17 | args: [ 18 | 'build', 19 | '-t', 'gcr.io/$PROJECT_ID/$_IMAGE:$BRANCH_NAME', 20 | '--cache-from', 'gcr.io/$PROJECT_ID/$_IMAGE:$BRANCH_NAME', 21 | '.' 22 | ] 23 | 24 | # slack deployment status 25 | - name: 'gcr.io/cloud-builders/curl' 26 | args: [ '-X', 'POST', '-H', 'Content-type: application/json', '--data', 27 | '{"text":"gcr.io/$PROJECT_ID/$_IMAGE:$BRANCH_NAME build completed!"}', '${_WEBHOOK_URL}' ] 28 | 29 | # store artifact 30 | images: ['gcr.io/$PROJECT_ID/$_IMAGE:$BRANCH_NAME'] 31 | 32 | # arguments 33 | substitutions: 34 | _IMAGE: docker_image_name # docker image name 35 | _WEBHOOK_URL: https://hooks.slack.com/services/ # Slack Webhook URL 36 | -------------------------------------------------------------------------------- /config/conf.d/core.conf: -------------------------------------------------------------------------------- 1 | # Hide nginx version information. 2 | server_tokens off; 3 | ssl_session_cache shared:SSL:10m; 4 | 5 | # Define the MIME types for files. 6 | include mime.types; 7 | default_type application/octet-stream; 8 | 9 | # enable request limit zone to prevent brute force attacks 10 | limit_req_zone $http_x_forwarded_for zone=one:16m rate=5r/m; 11 | 12 | # Format to use in log files 13 | log_format json '{ ' 14 | '"time": "$time_local", ' 15 | '"remote_addr": "$remote_addr", ' 16 | '"remote_user": "$remote_user", ' 17 | '"request_url": "$request", ' 18 | '"request_time": "$request_time", ' 19 | '"response_status": "$status", ' 20 | '"response_size": "$body_bytes_sent", ' 21 | '"referrer": "$http_referer", ' 22 | '"agent": "$http_user_agent", ' 23 | '"forwarded_for": "$http_x_forwarded_for", ' 24 | '"host": "$host" ' 25 | '}'; 26 | 27 | # Default log file 28 | # (this is only used when you don't override access_log on a server{} level) 29 | map $http_user_agent $log_ua { 30 | ~bingbot 0; 31 | ~Pingdom 0; 32 | ~Googlebot 0; 33 | ~Baiduspider 0; 34 | ~UptimeRobot 0; 35 | ~mod_pagespeed 0; 36 | ~NewRelicPinger 0; 37 | 38 | default 1; 39 | } 40 | 41 | error_log /var/log/nginx/error.log crit; 42 | access_log /var/log/nginx/access.log json if=$log_ua; # buffer=32k; 43 | 44 | # GEO IP support 45 | # https://medium.com/@karljohnson/geoip-discontinuation-upgrade-to-geoip2-with-nginxon-centos-c2a3dbcf8fd 46 | # https://echorand.me/posts/nginx-geoip2-mmdblookup/ 47 | map $http_x_forwarded_for $realip { 48 | ~^(\d+\.\d+\.\d+\.\d+) $1; 49 | default $remote_addr; 50 | } 51 | 52 | # How long to allow each connection to stay idle; longer values are better 53 | # for each individual client, particularly for SSL, but means that worker 54 | # connections are tied up longer. (Default: 65) 55 | # keepalive_timeout 30; 56 | # keepalive_requests 10000; 57 | 58 | # For performance reasons, on FreeBSD systems w/ ZFS 59 | # this option should be disabled as ZFS's ARC caches 60 | # frequently used files in RAM by default. 61 | sendfile on; 62 | 63 | # Tell Nginx not to send out partial frames; this increases throughput 64 | # since TCP frames are filled up before being sent out. (adds TCP_CORK) 65 | tcp_nopush on; 66 | tcp_nodelay on; 67 | 68 | # Other custom config variables 69 | # https://gist.github.com/denji/8359866 70 | client_header_timeout 3m; 71 | client_body_timeout 3m; 72 | client_max_body_size 100m; 73 | client_body_buffer_size 256k; 74 | client_header_buffer_size 3m; 75 | large_client_header_buffers 4 256k; 76 | 77 | # allow the server to close connection on non responding client, this will free up memory 78 | reset_timedout_connection on; 79 | 80 | # if client stop responding, free up memory -- default 60 81 | send_timeout 10; 82 | 83 | server_names_hash_max_size 2048; 84 | server_names_hash_bucket_size 256; 85 | 86 | variables_hash_max_size 2048; 87 | variables_hash_bucket_size 256; 88 | 89 | # http://www.revsys.com/12days/nginx-tuning/ 90 | open_file_cache max=200000 inactive=20s; 91 | open_file_cache_valid 30s; 92 | open_file_cache_min_uses 5; 93 | open_file_cache_errors off; 94 | -------------------------------------------------------------------------------- /config/conf.d/default.conf: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80 default_server; 3 | 4 | server_name _; 5 | 6 | location = /status { 7 | access_log off; 8 | stub_status; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /config/conf.d/geoip2.conf: -------------------------------------------------------------------------------- 1 | geoip2 /usr/share/GeoIP2/GeoLite2-Country.mmdb { 2 | $geoip2_metadata_country_build metadata build_epoch; 3 | $geoip2_data_country_code source=$realip country iso_code; 4 | $geoip2_data_country_name source=$realip country names en; 5 | } 6 | 7 | geoip2 /usr/share/GeoIP2/GeoLite2-City.mmdb { 8 | $geoip2_data_city_name source=$realip city names en; 9 | $geoip2_data_city_geonameid source=$realip city geoname_id; 10 | $geoip2_data_continent_code source=$realip continent code; 11 | $geoip2_data_continent_geonameid source=$realip continent geoname_id; 12 | $geoip2_data_continent_name source=$realip continent names en; 13 | $geoip2_data_country_geonameid source=$realip country geoname_id; 14 | $geoip2_data_country_iso source=$realip country iso_code; 15 | $geoip2_data_country_name source=$realip country names en; 16 | $geoip2_data_country_is_eu source=$realip country is_in_european_union; 17 | $geoip2_data_location_accuracyradius source=$realip location accuracy_radius; 18 | $geoip2_data_location_latitude source=$realip location latitude; 19 | $geoip2_data_location_longitude source=$realip location longitude; 20 | $geoip2_data_location_metrocode source=$realip location metro_code; 21 | $geoip2_data_location_timezone source=$realip location time_zone; 22 | $geoip2_data_postal_code source=$realip postal code; 23 | $geoip2_data_rcountry_geonameid source=$realip registered_country geoname_id; 24 | $geoip2_data_rcountry_iso source=$realip registered_country iso_code; 25 | $geoip2_data_rcountry_name source=$realip registered_country names en; 26 | $geoip2_data_rcountry_is_eu source=$realip registered_country is_in_european_union; 27 | $geoip2_data_region_geonameid source=$realip subdivisions 0 geoname_id; 28 | $geoip2_data_region_iso source=$realip subdivisions 0 iso_code; 29 | $geoip2_data_region_name source=$realip subdivisions 0 names en; 30 | } 31 | -------------------------------------------------------------------------------- /config/conf.d/gzip.conf: -------------------------------------------------------------------------------- 1 | # Compression 2 | 3 | # Enable static Gzip compressed. 4 | gzip_static on; 5 | 6 | # Enable Gzip compressed. 7 | gzip on; 8 | 9 | # Compression level (1-9). 10 | # 5 is a perfect compromise between size and cpu usage, offering about 11 | # 75% reduction for most ascii files (almost identical to level 9). 12 | gzip_comp_level 3; 13 | 14 | # Don't compress anything that's already small and unlikely to shrink much 15 | # if at all (the default is 20 bytes, which is bad as that usually leads to 16 | # larger files after gzipping). 17 | gzip_min_length 256; 18 | 19 | # Compress data even for clients that are connecting to us via proxies, 20 | # identified by the "Via" header (required for CloudFront). 21 | gzip_proxied any; 22 | 23 | # Tell proxies to cache both the gzipped and regular version of a resource 24 | # whenever the client's Accept-Encoding capabilities header varies; 25 | # Avoids the issue where a non-gzip capable client (which is extremely rare 26 | # today) would display gibberish if their proxy gave them the gzipped version. 27 | gzip_vary on; 28 | 29 | # Compress all output labeled with one of the following MIME-types. 30 | gzip_types 31 | application/atom+xml 32 | application/javascript 33 | application/json 34 | application/ld+json 35 | application/manifest+json 36 | application/rss+xml 37 | application/vnd.geo+json 38 | application/vnd.ms-fontobject 39 | application/x-font-ttf 40 | application/x-web-app-manifest+json 41 | application/xhtml+xml 42 | application/xml 43 | font/opentype 44 | image/bmp 45 | image/svg+xml 46 | image/x-icon 47 | text/cache-manifest 48 | text/css 49 | text/plain 50 | text/vcard 51 | text/vnd.rim.location.xloc 52 | text/vtt 53 | text/x-component 54 | text/x-cross-domain-policy; 55 | # text/html is always compressed by HttpGzipModule 56 | 57 | # This should be turned on if you are going to have pre-compressed copies (.gz) of 58 | # static files available. If not it should be left off as it will cause extra I/O 59 | # for the check. It is best if you enable this in a location{} block for 60 | # a specific directory, or on an individual server{} level. 61 | # gzip_static on; 62 | -------------------------------------------------------------------------------- /config/conf.d/pagespeed-css.conf: -------------------------------------------------------------------------------- 1 | pagespeed EnableFilters inline_css; 2 | pagespeed EnableFilters rewrite_css; 3 | pagespeed EnableFilters combine_css; 4 | pagespeed EnableFilters outline_css; 5 | pagespeed EnableFilters flatten_css_imports; 6 | pagespeed EnableFilters prioritize_critical_css; 7 | pagespeed EnableFilters inline_import_to_link; 8 | pagespeed EnableFilters inline_google_font_css; 9 | pagespeed EnableFilters move_css_above_scripts; 10 | pagespeed EnableFilters move_css_to_head; 11 | pagespeed EnableFilters fallback_rewrite_css_urls; 12 | pagespeed EnableFilters rewrite_style_attributes_with_url; 13 | -------------------------------------------------------------------------------- /config/conf.d/pagespeed-image.conf: -------------------------------------------------------------------------------- 1 | # image related optimization 2 | pagespeed EnableFilters resize_images; 3 | pagespeed EnableFilters rewrite_images; 4 | pagespeed EnableFilters lazyload_images; 5 | pagespeed EnableFilters jpeg_subsampling; 6 | pagespeed EnableFilters responsive_images; 7 | pagespeed EnableFilters convert_gif_to_png; 8 | pagespeed EnableFilters strip_image_meta_data; 9 | pagespeed EnableFilters strip_image_color_profile; 10 | pagespeed EnableFilters convert_jpeg_to_progressive; 11 | 12 | pagespeed EnableFilters dedup_inlined_images; 13 | pagespeed EnableFilters inline_preview_images; 14 | pagespeed EnableFilters resize_mobile_images; 15 | pagespeed EnableFilters inline_images; 16 | pagespeed EnableFilters recompress_jpeg; 17 | pagespeed EnableFilters recompress_png; 18 | pagespeed EnableFilters recompress_webp; 19 | pagespeed EnableFilters resize_rendered_image_dimensions; 20 | pagespeed EnableFilters convert_jpeg_to_webp; 21 | pagespeed EnableFilters convert_to_webp_lossless; 22 | pagespeed EnableFilters insert_image_dimensions; 23 | pagespeed EnableFilters sprite_images; 24 | -------------------------------------------------------------------------------- /config/conf.d/pagespeed-js.conf: -------------------------------------------------------------------------------- 1 | # javascript related optimization 2 | pagespeed UseExperimentalJsMinifier on; 3 | pagespeed EnableFilters rewrite_javascript; 4 | pagespeed EnableFilters inline_javascript; 5 | pagespeed EnableFilters combine_javascript; 6 | pagespeed EnableFilters canonicalize_javascript_libraries; 7 | -------------------------------------------------------------------------------- /config/conf.d/pagespeed.conf: -------------------------------------------------------------------------------- 1 | pagespeed off; 2 | 3 | pagespeed AdminPath /pagespeed_admin; 4 | pagespeed ConsolePath /pagespeed_console; 5 | pagespeed MessagesPath /ngx_pagespeed_message; 6 | pagespeed GlobalAdminPath /pagespeed_global_admin; 7 | pagespeed StatisticsPath /ngx_pagespeed_statistics; 8 | pagespeed GlobalStatisticsPath /ngx_pagespeed_global_statistics; 9 | 10 | # save on bandwidth and load resources directly from file system 11 | resolver 8.8.8.8; 12 | pagespeed UseNativeFetcher on; 13 | pagespeed NoTransformOptimizedImages on; 14 | pagespeed InPlaceResourceOptimization on; 15 | pagespeed ProcessScriptVariables on; 16 | pagespeed PreserveUrlRelativity on; 17 | pagespeed EnableCachePurge on; 18 | pagespeed Statistics on; 19 | pagespeed StatisticsLogging on; 20 | pagespeed RateLimitBackgroundFetches off; 21 | pagespeed RespectVary off; 22 | pagespeed CriticalImagesBeaconEnabled true; 23 | 24 | pagespeed FetchWithGzip on; 25 | pagespeed InPlaceWaitForOptimized on; 26 | pagespeed InPlaceRewriteDeadlineMs 100000; 27 | pagespeed CacheFlushPollIntervalSec 0; 28 | pagespeed HttpCacheCompressionLevel 9; 29 | 30 | pagespeed XHeaderValue "powered by sun"; 31 | pagespeed LogDir "/var/log/pagespeed"; 32 | 33 | pagespeed FileCachePath "/var/cache/ngx_pagespeed"; 34 | pagespeed FileCacheSizeKb 102400000; 35 | pagespeed FileCacheCleanIntervalMs 3600000; 36 | pagespeed FileCacheInodeLimit 5000000; 37 | 38 | pagespeed LRUCacheKbPerProcess 32000; 39 | pagespeed LRUCacheByteLimit 16384; 40 | pagespeed DefaultSharedMemoryCacheKB 500000; 41 | 42 | pagespeed MessageBufferSize 200000; 43 | pagespeed StatisticsLoggingIntervalMs 60000; 44 | pagespeed StatisticsLoggingMaxFileSizeKb 1024; 45 | 46 | pagespeed MaxSegmentLength 500; 47 | pagespeed MaxCombinedJsBytes 276480; 48 | 49 | # optimization filters 50 | pagespeed RewriteLevel CoreFilters; 51 | pagespeed EnableFilters extend_cache; 52 | 53 | # code related optimization 54 | pagespeed EnableFilters remove_comments; 55 | pagespeed EnableFilters collapse_whitespace; 56 | 57 | # DNS related optimization 58 | pagespeed EnableFilters insert_dns_prefetch; 59 | 60 | # additional settings 61 | pagespeed FetchHttps enable,allow_self_signed; 62 | 63 | pagespeed FetcherTimeoutMs 2000; 64 | pagespeed ImageMaxRewritesAtOnce 1000; 65 | pagespeed RewriteDeadlinePerFlushMs 2000; 66 | 67 | pagespeed NumRewriteThreads 16; 68 | pagespeed NumExpensiveRewriteThreads 64; 69 | pagespeed ImplicitCacheTtlMs 1800000; 70 | -------------------------------------------------------------------------------- /config/conf.d/status.conf: -------------------------------------------------------------------------------- 1 | server { 2 | listen 8080 default_server; 3 | 4 | server_name _; 5 | 6 | root /etc/nginx/html/; 7 | 8 | access_log off; 9 | 10 | location / { 11 | vhost_traffic_status_display; 12 | vhost_traffic_status_display_format html; 13 | } 14 | 15 | location = /health { 16 | add_header Content-Type text/plain; 17 | return 200 'OK'; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /config/fastcgi_params.orig: -------------------------------------------------------------------------------- 1 | fastcgi_param QUERY_STRING $query_string; 2 | fastcgi_param REQUEST_METHOD $request_method; 3 | fastcgi_param CONTENT_TYPE $content_type; 4 | fastcgi_param CONTENT_LENGTH $content_length; 5 | 6 | fastcgi_param SCRIPT_NAME $fastcgi_script_name; 7 | fastcgi_param REQUEST_URI $request_uri; 8 | fastcgi_param DOCUMENT_URI $document_uri; 9 | fastcgi_param DOCUMENT_ROOT $document_root; 10 | fastcgi_param SERVER_PROTOCOL $server_protocol; 11 | fastcgi_param REQUEST_SCHEME $scheme; 12 | 13 | fastcgi_param GATEWAY_INTERFACE CGI/1.1; 14 | fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; 15 | 16 | fastcgi_param REMOTE_ADDR $remote_addr; 17 | fastcgi_param REMOTE_PORT $remote_port; 18 | fastcgi_param SERVER_ADDR $server_addr; 19 | fastcgi_param SERVER_PORT $server_port; 20 | fastcgi_param SERVER_NAME $server_name; 21 | -------------------------------------------------------------------------------- /config/include/fastcgi_params: -------------------------------------------------------------------------------- 1 | # PHP only, required if PHP was built with --enable-force-cgi-redirect 2 | fastcgi_param REDIRECT_STATUS 200; 3 | 4 | fastcgi_param GEOIP_ADDR $remote_addr; 5 | fastcgi_param GEOIP_COUNTRY_CODE $geoip2_data_country_iso; 6 | fastcgi_param GEOIP_COUNTRY_NAME $geoip2_data_country_name; 7 | fastcgi_param GEOIP_REGION_CODE $geoip2_data_region_iso; 8 | fastcgi_param GEOIP_REGION_NAME $geoip2_data_region_name; 9 | fastcgi_param GEOIP_CITY_NAME $geoip2_data_city_name; 10 | fastcgi_param GEOIP_LATITUDE $geoip2_data_location_latitude; 11 | fastcgi_param GEOIP_LONGITUDE $geoip2_data_location_longitude; 12 | fastcgi_param GEOIP_POSTAL_CODE $geoip2_data_postal_code; 13 | fastcgi_param GEOIP_CONTINENT_CODE $geoip2_data_continent_code; 14 | fastcgi_param GEOIP_CONTINENT_NAME $geoip2_data_continent_name; 15 | 16 | # common line so we dont have to include it on every vhost 17 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 18 | 19 | # https://www.namhuy.net/3120/fix-nginx-upstream-response-buffered-temporary-file-error.html 20 | fastcgi_buffer_size 32k; 21 | fastcgi_buffers 256 16k; 22 | fastcgi_index index.php; 23 | 24 | # help PHP recognize HTTPS protocol behind proxy 25 | fastcgi_param HTTPS $php_https; 26 | -------------------------------------------------------------------------------- /config/include/pagespeed.conf: -------------------------------------------------------------------------------- 1 | pagespeed off; 2 | 3 | pagespeed LoadFromFileRuleMatch Disallow \.php; 4 | 5 | # Ensure requests for pagespeed optimized resources go to the pagespeed handler 6 | # and no extraneous headers get set. 7 | location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" { 8 | add_header "" ""; 9 | } 10 | location ~ "^/ngx_pagespeed_static/" { } 11 | location ~ "^/ngx_pagespeed_beacon$" { } 12 | -------------------------------------------------------------------------------- /config/include/rewrite-index.conf: -------------------------------------------------------------------------------- 1 | # Rewrite every request to index.php 2 | # configuration for PHP framework apps 3 | 4 | 5 | # serve static files directly 6 | location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico)$ { 7 | access_log off; 8 | expires max; 9 | add_header Pragma public; 10 | add_header Cache-Control "public, must-revalidate, proxy-revalidate"; 11 | } 12 | 13 | 14 | # remove the robots line if you want to use wordpress virtual robots.txt 15 | location = /robots.txt { access_log off; log_not_found off; } 16 | location = /favicon.ico { access_log off; log_not_found off; } 17 | location ~ /\. { access_log off; log_not_found off; deny all; } 18 | location ~ ~$ { access_log off; log_not_found off; deny all; } 19 | 20 | 21 | # unless the request is for a valid file, send to bootstrap 22 | # if (!-e $request_filename) { rewrite ^(.+)$ /index.php$is_args$args last; break; } 23 | location / { try_files $request_uri $request_uri/ /index.php$is_args$args; } 24 | 25 | 26 | index index.php index.html; 27 | -------------------------------------------------------------------------------- /config/include/rewrite-w3tc.conf: -------------------------------------------------------------------------------- 1 | # BEGIN W3TC Minify cache 2 | location ~ /wp-content/cache/minify.*\.js$ { 3 | types {} 4 | default_type application/x-javascript; 5 | add_header Vary "Accept-Encoding"; 6 | } 7 | location ~ /wp-content/cache/minify.*\.css$ { 8 | types {} 9 | default_type text/css; 10 | add_header Vary "Accept-Encoding"; 11 | } 12 | location ~ /wp-content/cache/minify.*js\.gzip$ { 13 | gzip off; 14 | types {} 15 | default_type application/x-javascript; 16 | add_header Vary "Accept-Encoding"; 17 | add_header Content-Encoding gzip; 18 | } 19 | location ~ /wp-content/cache/minify.*css\.gzip$ { 20 | gzip off; 21 | types {} 22 | default_type text/css; 23 | add_header Vary "Accept-Encoding"; 24 | add_header Content-Encoding gzip; 25 | } 26 | # END W3TC Minify cache 27 | # BEGIN W3TC Browser Cache 28 | gzip on; 29 | gzip_types text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon; 30 | # END W3TC Browser Cache 31 | # BEGIN W3TC Minify core 32 | rewrite ^/wp-content/cache/minify.*/w3tc_rewrite_test$ /wp-content/plugins/w3-total-cache/pub/minify.php?w3tc_rewrite_test=1 last; 33 | set $w3tc_enc ""; 34 | if ($http_accept_encoding ~ gzip) { 35 | set $w3tc_enc .gzip; 36 | } 37 | if (-f $request_filename$w3tc_enc) { 38 | rewrite (.*) $1$w3tc_enc break; 39 | } 40 | rewrite ^/wp-content/cache/minify/(.+/[X]+\.css)$ /wp-content/plugins/w3-total-cache/pub/minify.php?test_file=$1 last; 41 | rewrite ^/wp-content/cache/minify/(.+\.(css|js))$ /wp-content/plugins/w3-total-cache/pub/minify.php?file=$1 last; 42 | # END W3TC Minify core 43 | -------------------------------------------------------------------------------- /config/include/rewrite-wp.conf: -------------------------------------------------------------------------------- 1 | # WordPress multisite rewrite rules 2 | # with added protection for to disallow PHP execution on user upload folder 3 | 4 | # Yoast XML sitemaps 5 | location / { 6 | index index.php; 7 | try_files $request_uri $request_uri/ /index.php?$args; 8 | 9 | rewrite ^/sitemap_index\.xml$ /index.php?sitemap=1 last; 10 | rewrite ^/([^/]+?)-sitemap([0-9]+)?\.xml$ /index.php?sitemap=$1&sitemap_n=$2 last; 11 | } 12 | 13 | location /wp-admin/ { 14 | index index.php; 15 | try_files $request_uri $request_uri/ /index.php$args; 16 | } 17 | 18 | # Add trailing slash to /wp-admin requests 19 | rewrite /wp-admin$ $scheme::/$host$request_uri/ permanent; 20 | 21 | 22 | # serve static files directly 23 | location ~* \.(png|jpg|jpeg|gif|ico|woff|otf|ttf|eot|svg|txt|pdf|docx?|xlsx?)$ { 24 | access_log off; 25 | expires max; 26 | add_header Pragma public; 27 | add_header Vary "Accept-Encoding"; 28 | add_header Cache-Control "public, must-revalidate, proxy-revalidate"; 29 | add_header Access-Control-Allow-Origin "*"; 30 | add_header Access-Control-Allow-Methods "GET, OPTIONS"; 31 | } 32 | 33 | location ~* ^.+\.(eot|ttf|woff|svg|otf)$ { 34 | add_header Access-Control-Allow-Origin *; 35 | } 36 | 37 | # You may want to remove the robots line from drop to use a virtual robots.txt 38 | # or create a drop_wp.conf tailored to the needs of the wordpress configuration 39 | location = /robots.txt { access_log off; log_not_found off; } 40 | location = /favicon.ico { access_log off; log_not_found off; } 41 | location ~ /\. { access_log off; log_not_found off; deny all; } 42 | location ~ ~$ { access_log off; log_not_found off; deny all; } 43 | 44 | location = /50x.html { root html; } 45 | 46 | # Do not allow access to files giving away your WordPress version 47 | location ~ /(\.|wp-config\.php|readme\.html|license\.txt) { 48 | return 403; 49 | } 50 | 51 | # Block PHP files in uploads, content, and includes directory. 52 | location ~* /(?:uploads|files)/.*\.php$ { 53 | deny all; 54 | } 55 | -------------------------------------------------------------------------------- /config/nginx.conf: -------------------------------------------------------------------------------- 1 | user root; 2 | worker_processes auto; 3 | 4 | # number of file descriptors used for nginx 5 | # the limit for the maximum FDs on the server is usually set by the OS. 6 | # if you don't set FD's then OS settings will be used which is by default 2000 7 | # worker_rlimit_nofile 100000; 8 | 9 | error_log /var/log/nginx/error.log crit; 10 | pid /run/nginx.pid; 11 | 12 | events { 13 | worker_connections 1024; 14 | use epoll; 15 | multi_accept on; 16 | } 17 | 18 | http { 19 | aio threads; 20 | 21 | # custom vhost monitoring module 22 | # https://github.com/vozlt/nginx-module-vts#installation 23 | vhost_traffic_status_zone; 24 | 25 | # set custom headers 26 | more_set_headers 'X-Frontend: $hostname'; 27 | 28 | # includes 29 | include /etc/nginx/conf.d/*.conf; 30 | 31 | # help PHP recognize HTTPS protocol behind proxy 32 | map $http_x_forwarded_proto $php_https { 33 | default ''; 34 | https 'on'; 35 | } 36 | 37 | # include custom configurations 38 | } 39 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | 3 | services: 4 | nginx: 5 | build: . 6 | ports: 7 | - "80:80" 8 | - "8080:8080" 9 | container_name: nginx-pagespeed 10 | env_file: .env 11 | -------------------------------------------------------------------------------- /env-example: -------------------------------------------------------------------------------- 1 | MAKE_J=4 2 | NGINX_VERSION=1.13.3 3 | PAGESPEED_VERSION=1.12.34.2 4 | LIBPNG_VERSION=1.6.29 5 | 6 | ### add path to include extra configuration files: (default: off) 7 | NGINX_INCLUDE_PATH=/app/config/nginx/*.conf 8 | 9 | ### Include default server definition with health check: on|off (default: on) 10 | NGINX_DEFAULT_SERVER=on 11 | 12 | ### Include extra common fastcgi PHP GeoIP variables: on|off (default: on) 13 | NGINX_FASTCGI_GEOIP=on 14 | 15 | ### Google PageSpeed algorithm: on|off (default: off) 16 | NGINX_PAGESPEED=on 17 | 18 | ### PageSpeed image optimization: on|off (default: off) 19 | NGINX_PAGESPEED_IMG=on 20 | 21 | ### PageSpeed javascripts optimization: on|off (default: off) 22 | NGINX_PAGESPEED_JS=on 23 | 24 | ### PageSpeed style sheets optimization: on|off (default: off) 25 | NGINX_PAGESPEED_CSS=on 26 | 27 | ### PageSpeed cache storage: files|redis|memcached (default: files) 28 | NGINX_PAGESPEED_STORAGE=files 29 | 30 | ### PageSpeed Redis cache storage address and port: redis.host:port (default: none) 31 | NGINX_PAGESPEED_REDIS=redis.host:6379 32 | 33 | ### PageSpeed Memcached cache storage address and port: memcached.host:port (default: none) 34 | NGINX_PAGESPEED_MEMCACHED=memcached.host:11211 35 | -------------------------------------------------------------------------------- /geoip2/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/markhilton/docker-nginx-pagespeed/abe32a97940d285c71a7e8f95cdd8effb25f73ad/geoip2/.gitkeep -------------------------------------------------------------------------------- /scripts/docker-entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | /usr/local/bin/initialize.sh || exit 1 4 | 5 | echo "starting nginx web server..." 6 | 7 | set -e 8 | 9 | if [[ "$1" == -* ]]; then 10 | set -- nginx -g daemon off; "$@" 11 | fi 12 | 13 | exec "$@" 14 | -------------------------------------------------------------------------------- /scripts/initialize.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # use GeoIP MaxMind databases & expose fastcgi variables for PHP GeoIP 4 | # WARNING: since MaxMind does not offer automatic downloads 5 | # you have to upload GeoLite2-Country & GeoLite2-City yourself into container /usr/share/GeoIP2/ 6 | if [ -z ${NGINX_GEOIP+x} ]; then 7 | echo "env: NGINX_GEOIP not specified, default: [ off ]" 8 | rm /etc/nginx/conf.d/geoip2.conf 9 | cat /etc/nginx/fastcgi_params.orig > /etc/nginx/fastcgi_params 10 | else 11 | echo "env: NGINX_GEOIP: [ ${NGINX_GEOIP} ]" 12 | if [ "$NGINX_GEOIP" == "on" ]; then 13 | cat /etc/nginx/fastcgi_params.orig > /etc/nginx/fastcgi_params 14 | cat /etc/nginx/include/fastcgi_params >> /etc/nginx/fastcgi_params 15 | fi 16 | fi 17 | 18 | 19 | # setup pagespeed 20 | if [ -z ${NGINX_PAGESPEED+x} ]; then 21 | echo "env: NGINX_PAGESPEED not specified, default: [ off ]" 22 | else 23 | echo "env: NGINX_PAGESPEED: [ ${NGINX_PAGESPEED} ]" 24 | if [ "$NGINX_PAGESPEED" == "on" ]; then 25 | sed -i "/pagespeed off;/cpagespeed on;" /etc/nginx/conf.d/pagespeed.conf 26 | sed -i "/pagespeed off;/cpagespeed on;" /etc/nginx/include/pagespeed.conf 27 | else 28 | sed -i "/pagespeed on;/cpagespeed off;" /etc/nginx/conf.d/pagespeed.conf 29 | sed -i "/pagespeed on;/cpagespeed off;" /etc/nginx/include/pagespeed.conf 30 | fi 31 | fi 32 | 33 | 34 | # setup pagespeed image processing 35 | if [ -z ${NGINX_PAGESPEED_IMG+x} ]; then 36 | export NGINX_PAGESPEED_IMG=off 37 | fi 38 | 39 | echo "env: NGINX_PAGESPEED_IMG image optimization: [ ${NGINX_PAGESPEED_IMG} ]" 40 | if [ "$NGINX_PAGESPEED_IMG" == "on" ]; then 41 | sed -i "s/DisableFilters/EnableFilters/" /etc/nginx/conf.d/pagespeed-image.conf 42 | else 43 | sed -i "s/EnableFilters/DisableFilters/" /etc/nginx/conf.d/pagespeed-image.conf 44 | fi 45 | 46 | 47 | # setup pagespeed javascript processing 48 | if [ -z ${NGINX_PAGESPEED_JS+x} ]; then 49 | export NGINX_PAGESPEED_JS=off 50 | fi 51 | 52 | echo "env: NGINX_PAGESPEED_JS javascript optimization: [ ${NGINX_PAGESPEED_JS} ]" 53 | if [ "$NGINX_PAGESPEED_JS" == "on" ]; then 54 | sed -i "s/DisableFilters/EnableFilters/" /etc/nginx/conf.d/pagespeed-js.conf 55 | else 56 | sed -i "s/EnableFilters/DisableFilters/" /etc/nginx/conf.d/pagespeed-js.conf 57 | fi 58 | 59 | 60 | # setup pagespeed javascript processing 61 | if [ -z ${NGINX_PAGESPEED_CSS+x} ]; then 62 | export NGINX_PAGESPEED_CSS=off 63 | fi 64 | 65 | echo "env: NGINX_PAGESPEED_CSS stylesheets optimization: [ ${NGINX_PAGESPEED_CSS} ]" 66 | if [ "$NGINX_PAGESPEED_CSS" == "on" ]; then 67 | sed -i "s/DisableFilters/EnableFilters/" /etc/nginx/conf.d/pagespeed-css.conf 68 | else 69 | sed -i "s/EnableFilters/DisableFilters/" /etc/nginx/conf.d/pagespeed-css.conf 70 | fi 71 | 72 | 73 | # setup pagespeed cache backend 74 | if [ -z ${NGINX_PAGESPEED_STORAGE+x} ]; then 75 | echo "env: NGINX_PAGESPEED_STORAGE not specified, default: [ FILES ]" 76 | else 77 | echo "env: NGINX_PAGESPEED_STORAGE: [ ${NGINX_PAGESPEED_STORAGE} ]" 78 | if [ "$NGINX_PAGESPEED_STORAGE" == "redis" ]; then 79 | if [ -z ${NGINX_PAGESPEED_REDIS+x} ]; then 80 | echo "env: NGINX_PAGESPEED_STORAGE: [ ${NGINX_PAGESPEED_STORAGE} ], but NGINX_PAGESPEED_REDIS not set" 81 | rm -f /etc/nginx/conf.d/pagespeed-redis.conf 82 | else 83 | echo "env: NGINX_PAGESPEED_REDIS: [ ${NGINX_PAGESPEED_REDIS} ]" 84 | printf "# redis storage backend\n" > /etc/nginx/conf.d/pagespeed-redis.conf 85 | printf "pagespeed RedisServer \"${NGINX_PAGESPEED_REDIS}\";\n" >> /etc/nginx/conf.d/pagespeed-redis.conf 86 | printf "pagespeed RedisTimeoutUs 1000;\n" >> /etc/nginx/conf.d/pagespeed-redis.conf 87 | fi 88 | fi 89 | 90 | if [ "$NGINX_PAGESPEED_STORAGE" == "memcached" ]; then 91 | if [ -z ${NGINX_PAGESPEED_MEMCACHED+x} ]; then 92 | echo "env: NGINX_PAGESPEED_STORAGE: [ ${NGINX_PAGESPEED_STORAGE} ], but NGINX_PAGESPEED_MEMCACHED not set" 93 | rm -f /etc/nginx/conf.d/pagespeed-memcached.conf 94 | else 95 | echo "env: NGINX_PAGESPEED_MEMCACHED: [ ${NGINX_PAGESPEED_MEMCACHED} ]" 96 | printf "# memcached storage backend\n" > /etc/nginx/conf.d/pagespeed-memcached.conf 97 | printf "pagespeed MemcachedThreads 1;\n" >> /etc/nginx/conf.d/pagespeed-memcached.conf 98 | printf "pagespeed MemcachedServers \"${NGINX_PAGESPEED_MEMCACHED}\";\n" >> /etc/nginx/conf.d/pagespeed-memcached.conf 99 | fi 100 | fi 101 | fi 102 | 103 | 104 | # remove default server configuration if requested 105 | if [ "$NGINX_DEFAULT_SERVER" == "off" ]; then 106 | echo "env: NGINX_DEFAULT_SERVER: [ ${NGINX_DEFAULT_SERVER} ] - removing default server configuration" 107 | rm -f /etc/nginx/conf.d/default.conf 108 | fi 109 | 110 | 111 | # add custom nginx config include path 112 | if [ -z ${NGINX_INCLUDE_PATH+x} ] || [ "$NGINX_INCLUDE_PATH" == "" ]; then 113 | echo "env: NGINX_INCLUDE_PATH not specified: [ SKIP ]" 114 | else 115 | echo "env: NGINX_INCLUDE_PATH: [ ${NGINX_INCLUDE_PATH} ]" 116 | sed -i "/custom configurations/cinclude ${NGINX_INCLUDE_PATH}; # include custom configurations" /etc/nginx/nginx.conf 117 | 118 | for f in ${NGINX_INCLUDE_PATH}; do 119 | echo "conf: $f"; 120 | done 121 | fi 122 | --------------------------------------------------------------------------------