有关博客:
《Windows 编译安装 nginx 服务器 + rtmp 模块》、《Ubuntu 编译安装 nginx》、《Arm-Linux 移植 Nginx》
Host平台 :Ubuntu 16.04
Arm平台 : 3531d
nginx : 1.17.6 (本文完全适用于 1.15版本的 nginx)
arm-gcc :4.9.4
注意:这个和以往的交叉编译不一样,nginx的交叉编译依赖的库都是源码包,而不是最终的结果。
主机要做的事情:
##
##
#!/bin/sh
BASE=`pwd`
BUILD_HOST=arm-hisiv500-linux
ZLIB=zlib-
OPENSSL=openssl-1.0.2t
PCRE=pcre-8.30
NGINX=nginx-
FIN_INSTALL=/usr/${NGINX}
make_dirs() {
cd ${BASE}
mkdir compressed install source -p
}
download_package () {
cd ${BASE}/compressed
#下载包
wget -c https://www.zlib.net/${ZLIB}.tar.gz
wget https://www.openssl.org/source/${OPENSSL}.tar.gz
# 注意地址
wget -c https://jaist.dl.sourceforge.net/project/pcre/pcre/8.30/${PCRE}.tar.bz2
wget -c http://mirrors.sohu.com/nginx/${NGINX}.tar.gz
}
tar_package () {
cd ${BASE}/compressed
ls * > /tmp/list.txt
for TAR in `cat /tmp/list.txt`
do
tar -xf $TAR -C ../source
done
rm -rf /tmp/list.txt
}
pre_configure_nginx () {
cd ${BASE}/source/${NGINX}
# auto/cc/name
sed -r -i "/ngx_feature_run=yes/ s/.*/\tngx_feature_run=no/g" auto/cc/name
sed -r -i "/exit 1/ s/.*//1" auto/cc/name
# auto/types/sizeof
sed -r -i "/ngx\_size=\`$NGX\_AUTOTEST\`/ s/.\*/\\tngx\_size=4/g" auto/types/sizeof
#
sed -r -i "/PCRE\_CONF\_OPT=/ s/.\*/PCRE\_CONF\_OPT=--host=${BUILD\_HOST}/g" auto/options
}
configure_nginx () {
cd ${BASE}/source/${NGINX}
BUILD=`pwd`
./configure \
--builddir=${BUILD} \
--prefix=${FIN_INSTALL} \
--with-http_mp4_module \
--with-http_ssl_module \
--without-http_upstream_zone_module \
--with-openssl-opt=os/compiler:${BUILD_HOST}-gcc \
--with-cc=${BUILD_HOST}-gcc \
--with-cpp=${BUILD_HOST}-g++ \
--with-ld-opt=-lpthread \
--with-cc-opt='-D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64' \
--with-pcre=${BASE}/source/${PCRE} \
--with-openssl=${BASE}/source/${OPENSSL} \
--with-zlib=${BASE}/source/${ZLIB} \
--with-http_v2_module && echo "${FIN_INSTALL} with ${BUILD_HOST}" > ccinfo
}
pre_make_nginx () {
cd ${BASE}/source/${NGINX}
HEAD_FILE=`find . -name "ngx_auto_config.h"`
DEL_LINE=`sed -n "/NGX_CONFIGURE/=" ${HEAD_FILE}`
sed -i "${DEL_LINE}d" ${HEAD_FILE}
echo "#undef NGX_CONFIGURE " >> ${HEAD_FILE}
echo "#define NGX_CONFIGURE \"./configure\"" >> ${HEAD_FILE}
echo "#ifndef NGX_SYS_NERR" >> ${HEAD_FILE}
echo "#define NGX_SYS_NERR 132" >> ${HEAD_FILE}
echo "#endif" >> ${HEAD_FILE}
echo "#ifndef NGX\_HAVE\_SYSVSHM" >> ${HEAD\_FILE}
echo "#define NGX\_HAVE\_SYSVSHM 1" >> ${HEAD\_FILE}
echo "#endif" >> ${HEAD\_FILE}
# 删除makefile 多余的几行
DEL\_LINE=\`sed -n "/build\\:/=" Makefile | awk 'END {print}'\`
# 因为是有 行,删除以后文件会发生变化
sed -i "${DEL\_LINE}d" Makefile
sed -i "${DEL\_LINE}d" Makefile
DEL\_LINE=\`sed -n "/install\\:/=" Makefile | awk 'END {print}'\`
sed -i "${DEL\_LINE}d" Makefile
sed -i "${DEL\_LINE}d" Makefile
DEL\_LINE=\`sed -n "/modules\\:/=" Makefile | awk 'END {print}'\`
sed -i "${DEL\_LINE}d" Makefile
sed -i "${DEL\_LINE}d" Makefile
}
make_nginx () {
cd ${BASE}/source/${NGINX}
make -j4 && sudo make install && sudo mv ccinfo ${FIN_INSTALL}/ccinfo
}
sudo ls
make_dirs
#download_package
tar_package
pre_configure_nginx
configure_nginx
pre_make_nginx
make_nginx
这样应该就没有什么问题了。
arm板子:
整个目录 拷贝 到板子,具体以prefix指定的路径为准上
添加nginx有关库和运行路径环境变量\
完成nginx.conf的配置…(此步骤省略)
/usr/nginx/sbin/nginx -c /usr/nginx/conf/nginx.conf -p usr/nginx #启动nginx
编译nginx时指定外部模块
第三方模块下载地址:https://www.nginx.com/resources/wiki/modules/index.html
使第三方模块的生效方法: /configure --add-module=模块的路径
例如:
/configure --prefix=/usr/local/nginx-1.4.1 \
--with-http_stub_status_module \
--with-http_ssl_module --with-http_realip_module \
--with-http_image_filter_module \
--add-module=../ngx_pagespeed-master
正文到此结束,但为了让读者能够搞清楚脚本中的非常规指令的意义,本人保留了下文,以作为手动修改的参考依据。
nginx根目录下, 执行此脚本,再一步步排查错误。
cd ${BASE}/source/${NGINX}
echo ${BASE}/source/${NGINX}
BUILD=\`pwd\`
./configure \\
--builddir=${BUILD} \\
--prefix=${BASE}/install/nginx \\
--with-http\_mp4\_module \\
--with-http\_ssl\_module \\
--without-http\_upstream\_zone\_module \\
--with-openssl-opt=os/compiler:${BUILD\_HOST}-gcc \\
--with-cc=${BUILD\_HOST}-gcc \\
--with-cpp=${BUILD\_HOST}-g++ \\
--with-ld-opt=-lpthread \\
--with-cc-opt='-D\_FILE\_OFFSET\_BITS=64 -D\_\_USE\_FILE\_OFFSET64' \\
--with-pcre=${BASE}/source/${PCRE} \\
--with-openssl=${BASE}/source/${OPENSSL} \\
--with-zlib=${BASE}/source/${ZLIB} \\
--with-http\_v2\_module
提示
checking for OS
./configure: error: C compiler arm-hisiv500-linux-gcc is not found
make: *** No rule to make target 'build', needed by 'default'. Stop.
解决方法:
修改 auto/cc/name
ngx_feature_run=yes
手机扫一扫
移动阅读更方便
你可能感兴趣的文章