自动安装
-
安装文档
https://www.modpagespeed.com/doc/build_ngx_pagespeed_from_source -
使用自动安装脚本安装, 安装过程build时,如果需要添加参数,可以使用
nginx -V
将之前已经安装的版本参数导出
bash <(curl -f -L -sS https://ngxpagespeed.com/install) \
--nginx-version latest
- 安装过程一路点击
y
, 最后如果无意外会出现安装成功提示
Nginx installed with ngx_pagespeed support compiled-in.
If this is a new installation you probably need an init script to
manage starting and stopping the nginx service. See:
http://wiki.nginx.org/InitScripts
You'll also need to configure ngx_pagespeed if you haven't yet:
https://developers.google.com/speed/pagespeed/module/configuration
手动安装
#!/bin/bash -l
# author: dengbeiquan
# data: Mon, Nov 6, 2017 4:52:44 PM
# desc: 手动安装 pagespeed
# 参考: https://www.coderxing.com/nginx-pagespeed-module.html
NGINX_MODULES_PATH='/etc/nginx/modules'
NGINX_VERSION='1.12.2' # stable version
NPS_VERSION='1.12.34.2' # bate version
#PS_NGX_EXTRA_FLAGS="--with-cc=/opt/rh/devtoolset-2/root/usr/bin/gcc" # gcc < 4.8 时,需要升级的额外选项
PS_NGX_EXTRA_FLAGS=""
NGINX_BIN='/usr/sbin/nginx'
BASE_DIR=$(cd `dirname $0`; pwd)
# First download ngx_pagespeed:
download_ngx_pagespeed()
{
echo '[tips:] First download ngx_pagespeed'
cd $BASE_DIR && \
[ -f v${NPS_VERSION}-beta.zip ] || wget https://github.com/pagespeed/ngx_pagespeed/archive/v${NPS_VERSION}-beta.zip && \
unzip v${NPS_VERSION}-beta.zip && \
cd ngx_pagespeed-${NPS_VERSION}-beta/ && \
psol_url=https://dl.google.com/dl/page-speed/psol/${NPS_VERSION}.tar.gz && \
[ -e scripts/format_binary_url.sh ] && psol_url=$(scripts/format_binary_url.sh PSOL_BINARY_URL) && \
wget ${psol_url} && \
tar -xzf $(basename ${psol_url}) # extracts to psol/
}
# Download and build nginx with support for pagespeed
download_build_nginx_with_pagespped()
{
echo '[tips:] Download and build nginx with support for pagespeed'
# 查看原来 nginx 编译时的配置
NGINX_BUILD_CONF=`$NGINX_BIN -V 2>&1 >/dev/null | grep 'configure' --color | awk -F':' '{print $2;}'`
# 动态模块编译
NGINX_BUILD_CONF="$NGINX_BUILD_CONF --add-dynamic-module=$BASE_DIR/ngx_pagespeed-${NPS_VERSION}-beta ${PS_NGX_EXTRA_FLAGS}"
echo $NGINX_BUILD_CONF
# 下载编译
cd $BASE_DIR && \
[ -f nginx-${NGINX_VERSION}.tar.gz ] || wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz && \
tar -xzf nginx-${NGINX_VERSION}.tar.gz && \
cd nginx-${NGINX_VERSION}/ && \
./configure $NGINX_BUILD_CONF && \
make
# make install # build with exist nginx will not need to install
}
# copy and 写入加载模块指令
load_pagespeed()
{
echo '[tips:] cppy and 写入加载模块指令'
cp $BASE_DIR/nginx-${NGINX_VERSION}/objs/ngx_pagespeed.so $NGINX_MODULES_PATH && \
echo 'load_module "modules/ngx_pagespeed.so";' > $NGINX_MODULES_PATH/ngx_pagespeed.conf
}
# start to run
download_ngx_pagespeed && \
download_build_nginx_with_pagespped && \
load_pagespeed
网友评论