1. Nginx准备资料:
Zlib下载
Pcre下载
官网: https://sourceforge.net/projects/pcre/files/
Openssl下载
官网: https://www.openssl.org/source/
Nginx下载
官网:http://nginx.org/en/download.html
2. 解压:
tar –xvf zlib-1.2.11.tar.gz
tar –xvf pcre-8.40.zip
tar –xvf openssl-1.0.1d.tar.gz
tar –xvf nginx-1.8.1.tar.gz
注意:为了保证后续可以正确编译和移植
Openssl: openssl-1.0.1d.tar.gz
Nginx:nginx-1.8.1.tar.gz
3. 修改检测参数:
vi nginx-1.8.1/auto/cc/name
将其中的21行exit 1注释
否则会报以下错误:
./configure:error: C compiler /home/shanlink/Cross_compile/arm-hisiv200-
linux/bin/arm-hisiv200-linux-gnueabi-gcc is not found
导致原因: 自动启动编译器检测编译工具,而交叉编译的软件无法执行故报错。
4. 修改关联参数:
vi nginx-1.8.1/auto/types/sizeof
将其中的ngx_test="$CC $CC_TEST_FLAGS $CC_AUX_FLAGS \的$CC改为"gcc $CC_TEST_FLAGS $CC_AUX_FLAGS \
(此处关联各定义类型的长度大小,改为gcc检测即可)
否则会报以下错误:
./configure:error: can not detect int size
5 配置nginx:新建一个文件,拷贝如下脚本内容至文件(注意修改对应的交叉编译工具路径),并将文件改成compile.sh,拷贝compile.sh至nginx-1.8.1目录,执行./compile.sh
#!/bin/bash
#cross compile tools (whereisarm-hisiv200-linux-gcc)
CC_PATH=/opt/hisi-linux/x86-arm/arm-hisiv200-linux/target/bin/arm-hisiv200-linux-gcc
CPP_PATH=/opt/hisi-linux/x86-arm/arm-hisiv200-linux/target/bin/arm-hisiv200-linux-g++
#dependency Library
PCRE_PATH=$(pwd)/../pcre-8.40
ZLIB_PATH=$(pwd)/../zlib-1.2.11
SSL_PATH=$(pwd)/../openssl-1.0.1d
#output results path
OUT_PATH=../
#configure parameters
./configure --group=root--user=root --prefix=$OUT_PATH \
--with-http_ssl_module--with-openssl=$SSL_PATH --with-zlib=$ZLIB_PATH --with-pcre=$PCRE_PATH \
--with-cc=$CC_PATH --with-cpp=$CPP_PATH
6. 修改生成的Makefile文件:
vi nginx-1.8.1/objs/Makefile
6.1 pcre编译处 ./configure--disable-shared 后添加 --host=arm-hisiv200-linux
6.2 Ssl编译处删除config所在行
6.3 在6.2删除的行处增加 (注意:路径根据自己的进行修改)
&& ./config no-asm--cross-compile-prefix=/opt/hisi-linux/x86-arm/arm-hisiv200-linux/target/bin/arm-hisiv200-linux---prefix=/home/heya/nginx/nginx-1.8.1/../openssl-1.0.1d/.openssl no-shared \
&& sed -i 's/-m32//g'/home/heya/nginx/nginx-1.8.1/../openssl-1.0.1d/Makefile \
&& sed -i 's/-Werror//g'/home/heya/nginx/nginx-1.8.1/../openssl-1.0.1d/Makefile \
7. 修改nginx配置
vi nginx-1.8.1/objs/ngx_auto_config.h
添加如下配置:
#ifndef NGX_SYS_NERR
#define NGX_SYS_NERR 132
#endif
#ifndef NGX_HAVE_SYSVSHM
#define NGX_HAVE_SYSVSHM 1
#endif
8. 执行make编译
9. 执行make install安装
10. 生成的移植文件在nginx-1.8.1的上级目录中,包括:conf,html,logs,sbin文件夹
11. 新建nginx文件夹,将上面生成的文件夹拷贝到此文件夹内,将nginx移植到目标板上,执行sbin中的nginx就可以了启动http服务器。具体命令:./nginx