1:下载相关源码
nginx-1.20.2.tar.tar.gz
nginx-rtmp-module-master.zip
zlib-1.3.tar.gz
openssl-1.1.1i.tar.gz
源码下载:nginxrtmp服务器交叉编译相关源码资源-CSDN文库
2:解压源码并配置
tar zxvf nginx-1.20.2.tar.gz
unzip nginx-rtmp-module-master.zip
tar zxvf zlib-1.3.tar.gz
tar zxvf openssl-1.1.1i.tar.gz
cd nginx-1.20.2/
./configure --prefix=/usr/local/nginx/ --with-cc=aarch64-linux-gnu-gcc --add-module=../nginx-rtmp-module-master --without-http_rewrite_module --without-http_fastcgi_module --without-http_charset_module --without-http_ssi_module --without-http_userid_module --without-http_auth_basic_module --without-http_geo_module --without-http_map_module --without-http_split_clients_module --without-http_referer_module --without-http_uwsgi_module --without-http_scgi_module --without-http_memcached_module --without-http_memcached_module --without-http_limit_conn_module --without-http_limit_req_module --without-http_empty_gif_module --without-http_browser_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --without-http_upstream_zone_module --with-openssl=../openssl-1.1.1i --with-zlib=../zlib-1.3
问题1:./configure: error: C compiler aarch64-linux-gnu-gcc is not found
原因分析:configure首先会编译一个小测试程序,通过测试其运行结果来判断编译器是否能正常工作,由于交叉编译器所编译出的程序是无法在编译主机上运行的,故而产生此错误。
解决办法:编辑auto/cc/name文件,将21行的“exit 1”注释掉(令测试程序不会报错)
问题2:checking for int size ...auto/types/sizeof: line 43: objs/autotest: cannot execute binary file: Exec format error bytes ./configure: error: can not detect int size
原因分析: 因为cc编译后的程序无法本地执行导致。
解决办法: 编辑auto/types/sizeof文件,将43行的“ngx_size=`$NGX_AUTOTEST`”改为“ngx_size=4”
3:编译
make -j12
问题3:./openssl-1.1.1i/.openssl/lib/libssl.a(methods.o): Relocations in generic ELF (EM: 62) ../openssl-1.1.1i/.openssl/lib/libssl.a: error adding symbols: File in wrong format
原因分析:交叉编译器没有传到openssl 导致oppnssl使用gcc编译的文件无法识别
解决办法:
编辑auto/lib/openssl/make文件,将54行:
&& ./config --prefix=$ngx_prefix no-shared no-threads $OPENSSL_OPT \\
修改为:
&& ./config --prefix=$ngx_prefix no-shared no-asm no-async no-threads --cross-compile-prefix=aarch64-himix100-linux- $OPENSSL_OPT \\
&& sed -i 's/-m64/ /g' Makefile \\
问题4:undefined reference to `ngx_shm_alloc'
undefined reference to `ngx_shm_free'
undefined reference to `ngx_shm_free'
解决办法:编辑objs/ngx_auto_config.h文件添加下面内容
#ifndef NGX_HAVE_SYSVSHM
#define NGX_HAVE_SYSVSHM 1
#endif
4:安装及配置
1: make install
2: cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx_rtmp.conf
3:vi nginx_rtmp.conf 添加rtmp配置
rtmp {
server {
listen 1935;
chunk_size 4000;
application live {
live on;
}
}
}
4: 将/usr/local/nginx拷贝到开发板
5:开发板运行
1:export PATH=$PATH:/usr/local/nginx/sbin
2:nginx -c /usr/local/nginx/conf/nginx-rtmp.conf
问题5:nginx: [emerg] getpwnam("nobody") failed (2: No such file or directory)
原因分析:配置是没有指定运行用户和组,使用了默认nobody,但开发板又没有此用户,所以报错
解决办法:1:修改config 指定开发板存在的用户和组
2:修改nginx-rtmp.conf 指定用户
3:开发板新增用户和组
问题6:问题5依旧存在,进一步分析,发现开发板系统函数getpwnam 返回空指针获取不到用户信息,导致错误。
解决办法:修改源码跳过getpwnam函数,直接设置开发板已经存在的用户信息