Isto é como compilar o nginx 1.10.2 com o pagespeed 1.11.33.4 no CentOS 7
yum update
yum install wget curl gcc-c++ pcre-devel zlib-devel make unzip openssl-devel
mkdir /root/custom-nginx
cd /root/custom-nginx
NGINX_VERSION=1.10.2 ### copy and paste, place your nginx version you want to install
wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz
tar zxvf nginx-${NGINX_VERSION}.tar.gz
ls -la ### check downloaded version
cd /root/custom-nginx/nginx-${NGINX_VERSION}/src/http/modules/
acesse esta página para encontrar a versão mais recente
-beta não significa não versão estável, 1.11.33.4 é versão estável
NPS_VERSION=1.11.33.4 ### copy and paste, place your pagespeed version you want to install
wget https://github.com/pagespeed/ngx_pagespeed/archive/release-${NPS_VERSION}-beta.zip -O release-${NPS_VERSION}-beta.zip
unzip release-${NPS_VERSION}-beta.zip
mv ngx_pagespeed-release-${NPS_VERSION}-beta ngx_pagespeed
cd ngx_pagespeed
wget https://dl.google.com/dl/page-speed/psol/${NPS_VERSION}.tar.gz
tar -xzvf ${NPS_VERSION}.tar.gz
cd /root/custom-nginx/nginx-${NGINX_VERSION}/
configuração comum (nginx instalado a partir do repo + pagepeed)
./configure --add-module=/root/custom-nginx/nginx-${NGINX_VERSION}/src/http/modules/ngx_pagespeed --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-file-aio --with-threads --with-ipv6 --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_ssl_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic'
make && make install
Então
nano /etc/init.d/nginx
Faça o arquivo e cole o código:
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: NGINX is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user='$nginx -V 2>&1 | grep "configure arguments:.*--user=" | sed 's/[^*]*--user=\([^ ]*\).*//g' -'
if [ -n "$user" ]; then
if [ -z "'grep $user /etc/passwd'" ]; then
useradd -M -s /bin/nologin $user
fi
options='$nginx -V 2>&1 | grep 'configure arguments:''
for opt in $options; do
if [ 'echo $opt | grep '.*-temp-path'' ]; then
value='echo $opt | cut -d "=" -f 2'
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
fi
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
Verifique se a pasta / var / ngx_pagespeed_cache é criada por nginx
edite o /etc/nginx/your-domain.conf ### e coloque suas configurações
###PAGESPEED###
pagespeed on;
pagespeed FileCachePath /var/ngx_pagespeed_cache;
##EXTRA FILTERS
#--> JAVASCRIPT
pagespeed EnableFilters canonicalize_javascript_libraries,rewrite_javascript,combine_javascript,inline_javascript,make_google_analytics_async ;
#--> CSS
pagespeed EnableFilters move_css_above_scripts,move_css_to_head,rewrite_style_attributes,inline_css,inline_google_font_css ;
#--> IMAGES
pagespeed EnableFilters convert_to_webp_lossless,sprite_images,resize_mobile_images,inline_preview_images ;
#--> HTML
pagespeed EnableFilters collapse_whitespace,remove_comments,extend_cache ;
#
##EXTRA MODS
pagespeed LazyloadImagesAfterOnload off ;
pagespeed UseExperimentalJsMinifier on ;
pagespeed LowercaseHtmlNames on ;
pagespeed PreserveUrlRelativity on ;
pagespeed XHeaderValue "Modified By dimitrios" ;
#pagespeed ForceCaching on ;
###PAGESPEED###
Teste de cofiguração
/usr/sbin/nginx -V ### must include pagespeed
/usr/sbin/nginx -t ### syntax must be ok
Atenção! Desative seu repositório para evitar a atualização do nginx!