Hi3559A aarch64-himix100-linux
nginx依赖以下模块:
zlib 库(zlib-1.2.11):http://www.zlib.net/
pcre 库(pcre-8.42):http://www.pcre.org/
openssl库(openssl-1.1.0h) :http://www.openssl.org/source/
nginx(nginx-1.14.2):http://nginx.org/en/download.html
Nginx upload module:Nginx upload module下载
暂时未加入zlib
configure配置参照:http://www.ttlsa.com/nginx/nginx-configure-descriptions/
configure配置:
./configure --prefix=./ --with-http_ssl_module --with-cc=/opt/hisi-linux/x86-arm/aarch64-himix100-linux/host_bin/aarch64-linux-gnu-gcc --with-cpp=/opt/hisi-linux/x86-arm/aarch64-himix100-linux/host_bin/aarch64-linux-gnu-cpp --with-pcre=pcre-8.42 --with-openssl=openssl-1.1.0h --without-http_gzip_module --without-http_upstream_zone_module --add-module=nginx-rtmp-module --add-module=nginx-upload-module
make -j4
填坑参照:https://www.jianshu.com/p/5d9b60f7b262
踩坑一,configure的时候报错
checking for C compiler ... found but is not working
./configure: error: C compiler aarch64-himix100-linux-gcc is not found
这是因为nginx编译的时候除了检查cc是否存在,还需要执行编译后的程序。很明显交叉编译的程序无法执行。解决办法
vi auto/cc/name
ngx_feature="C compiler"
ngx_feature_name=
ngx_feature_run=yes
==> ngx_feature_run=no
踩坑二,configure的时候报错
checking for int size ...objs/autotest: 1: objs/autotest: Syntax error: word unexpected (expecting ")")
bytes
./configure: error: can not detect int size
同样也是因为cc编译后的程序无法本地执行导致。解决办法
vi auto/types/sizeof
ngx_test="$CC $CC_TEST_FLAGS $CC_AUX_FLAGS \
==> ngx_test="gcc $CC_TEST_FLAGS $CC_AUX_FLAG \
if [ -x $NGX_AUTOTEST ]; then
ngx_size=`$NGX_AUTOTEST`
==> ngx_size=4
踩坑三,make的时候报错
cd /home/src/pcre-8.42
&& if [ -f Makefile ]; then make distclean; fi
&& CC="aarch64-himix100-linux-gcc" CFLAGS="--host=aarch64-himix100-linux -pipe"
./configure --disable-shared
...
configure: error: in `/home/src/pcre-8.42':
configure: error: C compiler cannot create executables
这是因为编译pcre的时候,nginx没有正确设置交叉编译链。解决
vi auto/options
PCRE_CONF_OPT=
==> PCRE_CONF_OPT=--host=aarch64-himix100-linux
踩坑四,make的时候报错
src/core/ngx_rwlock.c:125:2: error: #error ngx_atomic_cmp_set() is not defined!
报错的地方,nginx的源码是这样的
#if (NGX_HTTP_UPSTREAM_ZONE || NGX_STREAM_UPSTREAM_ZONE)
#error ngx_atomic_cmp_set() is not defined!
#endif
解决办法,在configure的时候加上--without-http_upstream_zone_module
踩坑五,make的时候报错
src/os/unix/ngx_errno.c: In function ‘ngx_strerror’:
src/os/unix/ngx_errno.c:37:31: error: ‘NGX_SYS_NERR’ undeclared (first use in this function)
msg = ((ngx_uint_t) err < NGX_SYS_NERR) ? &ngx_sys_errlist[err]:
出错的原因仍然是因为交叉编译程序无法本地运行,导致NGX_SYS_NERR宏没有赋值。解决办法,手动编辑 objs/ngx_auto_config.h,加上
#ifndef NGX_SYS_NERR
#define NGX_SYS_NERR 132
#endif
踩坑六,make的时候报错
/home/src/openssl-OpenSSL_1_1_0i/.openssl/lib/libssl.a: error adding symbols: File format not recognized
collect2: error: ld returned 1 exit status
objs/Makefile:236: recipe for target 'objs/nginx' failed
这是SSL编译的时候调用了x86的gcc,而非交叉编译gcc导致的。解决办法
vi auto/lib/openssl/make
&& ./config --prefix=$ngx_prefix no-shared no-threads $OPENSSL_OPT \
改为
&& ./Configure --prefix=$ngx_prefix no-shared no-threads --cross-compile-prefix=aarch64-himix100-linux- linux-generic64 \
踩坑七,make的时候报错
objs/src/core/ngx_cycle.o: In function 'ngx_init_cycle':
/home/src/nginx-1.14.0/src/core/ngx_cycle.c:476: undefined reference to 'ngx_shm_alloc'
/home/src/nginx-1.14.0/src/core/ngx_cycle.c:685: undefined reference to 'ngx_shm_free'
解决办法
vi objs/ngx_auto_config.h
#ifndef NGX_HAVE_SYSVSHM
#define NGX_HAVE_SYSVSHM 1
#endif
http {
......
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
add_header Access-Control-Allow-Origin *;
root /mtd/seemmo/programs/web;
index index.html index.htm;
}
# upload file
location /upload_file {
# 转到后台处理URL
#upload_pass /uploadHandle;
# 文件上传以后转交给后端的php代码处理
# 这个位置是否是文章上传成功到指定目录后 戳发后台处理的地址
upload_pass /uploadvideosBackendDispose;
# 临时保存路径可以使用散列
upload_store /tmp/data/videos/;
# 上传文件的权限,rw表示读写 r只读
upload_store_access user:rw;
# 这里写入http报头,pass到后台页面后能获取这里set的报头字段
upload_set_form_field "${upload_field_name}_name" $upload_file_name;
upload_set_form_field "${upload_field_name}_content_type" $upload_content_type;
upload_set_form_field "${upload_field_name}_path" $upload_tmp_path;
# Upload模块自动生成的一些信息,如文件大小与文件md5值
upload_aggregate_form_field "${upload_field_name}_md5" $upload_file_md5;
upload_aggregate_form_field "${upload_field_name}_size" $upload_file_size;
# 允许的字段,允许全部可以 "^.*$"
#upload_pass_form_field "^submit$|^description$";
upload_pass_form_field "^.*$";
# 每秒字节速度控制,0表示不受控制,默认0
upload_limit_rate 0;
# 如果pass页面是以下状态码,就删除此次上传的临时文件
upload_cleanup 400 404 499 500-505;
}
# 将请求转到后端的地址处理
location /uploadvideosBackendDispose {
proxy_pass http://web.com/app/demo_pac/upload_handler/upload_videos;
}
}
}