Skip to content

Instantly share code, notes, and snippets.

@MiguelTVMS
Created April 8, 2017 16:19
Show Gist options
  • Save MiguelTVMS/749bd7bd2114938e3ea7a8b005289922 to your computer and use it in GitHub Desktop.
Save MiguelTVMS/749bd7bd2114938e3ea7a8b005289922 to your computer and use it in GitHub Desktop.
Rodando NG_PageSpeed & Nginx utilizando Docker - Dockerfile
FROM debian:jessie
RUN apt-get -y update && apt-get install -y \
wget \
build-essential \
libpcre3-dev \
zlib1g-dev
ENV NGINX_VERSION=1.11.12
ENV NPS_VERSION=1.11.33.5
ENV PSOL_VERSION=1.11.33.4
ENV SUBS_VERSION=0.6.4
# Criamos a pasta que conterá o nosso código fonte.
RUN ["mkdir","/usr/nginx_source/"]
WORKDIR "/usr/nginx_source/"
# Baixamos o código do Nginx da versão que selecionamos.
RUN wget -O nginx.tar.gz \
http://nginx.org/download/nginx-$NGINX_VERSION.tar.gz
RUN tar -xvzf nginx.tar.gz
# Baixamos o módulo de substituição de texto.
RUN wget -O ngx_http_substitutions_filter_module.tar.gz \
https://github.com/yaoweibin/ngx_http_substitutions_filter_module/archive/v$SUBS_VERSION.tar.gz
RUN tar -xzvf ngx_http_substitutions_filter_module.tar.gz
# Baixamos agora o código fonte do PageSpeed.
RUN wget -O ngpagespeed.tar.gz \
https://github.com/pagespeed/ngx_pagespeed/archive/latest-stable.tar.gz
RUN tar -xvzf ngpagespeed.tar.gz
WORKDIR "/usr/nginx_source/ngx_pagespeed-latest-stable/"
RUN wget https://dl.google.com/dl/page-speed/psol/$PSOL_VERSION.tar.gz
RUN tar -xzvf $PSOL_VERSION.tar.gz
# Compilando o Nginx
WORKDIR "/usr/nginx_source/nginx-$NGINX_VERSION/"
RUN ./configure \
--add-module=/usr/nginx_source/ngx_pagespeed-latest-stable \
--add-module=/usr/nginx_source/ngx_http_substitutions_filter_module-$SUBS_VERSION
RUN make
RUN make install
# Removendo todo o código fonte baixado para a compilação.
RUN rm -rf /usr/nginx_source
# Limpando os pacotes desnecessários para e execução do container.
RUN apt-get purge -y \
wget \
build-essential \
libpcre3-dev \
zlib1g-dev \
&& apt-get autoremove -y
# Estas são as configurações que utilizamos no nginx.
ENV NGX_LOGLEVEL debug
ENV NGX_UPSTREAM_NAME www.google.com
ENV NGX_UPSTREAM_SERVER www.google.com:80
# Estas são as configurações que utilizaremos no PageS
ENV NPS_ENABLED on
ENV NPS_LOWERCASEHTMLNAMES on
ENV NPS_RESPECTVARY off
ENV NPS_DISABLEREWRITEONNOTRANSFORM on
ENV NPS_MODIFYCACHINGHEADERS on
ENV NPS_XHEADERVALUE "Powered By jmtvms/ngx_pagespeed"
ENV NPS_ENABLEFILTERS rewrite_javascript,move_css_to_head,rewrite_css,combine_css,combine_javascript,collapse_whitespace,dedup_inlined_images,elide_attributes
# Vamos copiar alguns arquivos para dentro do container.
COPY content/nginx.conf /usr/local/nginx/conf/
COPY content/robots.txt /usr/local/nginx/html/
# Estas linhas servem para que os logs do Nginx sejam apresentadas no console do container.
RUN ln -sf /dev/stdout /usr/local/nginx/logs/access.log
RUN ln -sf /dev/stderr /usr/local/nginx/logs/error.log
ENTRYPOINT \sed -i 's/%%NGX_LOGLEVEL%%/'"$NGX_LOGLEVEL"'/g' /usr/local/nginx/conf/nginx.conf && \
sed -i 's/%%NGX_UPSTREAM_NAME%%/'"$NGX_UPSTREAM_NAME"'/g' /usr/local/nginx/conf/nginx.conf && \
sed -i 's/%%NGX_UPSTREAM_SERVER%%/'"$NGX_UPSTREAM_SERVER"'/g' /usr/local/nginx/conf/nginx.conf && \
sed -i 's/%%NPS_ENABLED%%/'"$NPS_ENABLED"'/g' /usr/local/nginx/conf/nginx.conf && \
sed -i 's/%%NPS_LOWERCASEHTMLNAMES%%/'"$NPS_LOWERCASEHTMLNAMES"'/g' /usr/local/nginx/conf/nginx.conf && \
sed -i 's/%%NPS_ENABLEFILTERS%%/'"$NPS_ENABLEFILTERS"'/g' /usr/local/nginx/conf/nginx.conf && \
sed -i 's/%%NPS_RESPECTVARY%%/'"$NPS_RESPECTVARY"'/g' /usr/local/nginx/conf/nginx.conf && \
sed -i 's/%%NPS_DISABLEREWRITEONNOTRANSFORM%%/'"$NPS_DISABLEREWRITEONNOTRANSFORM"'/g' /usr/local/nginx/conf/nginx.conf && \
sed -i 's/%%NPS_MODIFYCACHINGHEADERS%%/'"$NPS_MODIFYCACHINGHEADERS"'/g' /usr/local/nginx/conf/nginx.conf && \
/usr/local/nginx/sbin/./nginx -g 'daemon off;';
CMD [""]
EXPOSE 80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment