栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

nginx 交叉编译

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

nginx 交叉编译

环境:

Linux CentOS6.9 2.6.32-696.el6.x86_64

软件版本:

nginxhttp://nginx.org/download/nginx-1.18.0.tar.gz
opensslhttps://www.openssl.org/source/old/1.1.1/openssl-1.1.1f.tar.gz
zlibhttps://codeload.github.com/madler/zlib/tar.gz/refs/tags/v1.2.11
pcrehttps://nchc.dl.sourceforge.net/project/pcre/pcre/8.45/pcre-8.45.tar.gz

下载上面的软件包之后解压,可得:

.
├── nginx-1.18.0
├── openssl-1.1.1f
├── pcre-8.45
└── zlib-1.2.11

nginx 官方文档:http://nginx.org/en/docs/configure.html

生成 Makefile

编辑以下脚本(build.sh):

#!/bin/sh

# 该脚本放在 nginx-1.18.0 目录下执行

BUILD_PATH=$(pwd)
CROSS_CC=${你的编译器目录}/arm-buildroot-linux-gnueabi-

ZLIB_PATH=${BUILD_PATH}/../zlib-1.2.11
PCRE_PATH=${BUILD_PATH}/../pcre-8.45
OPENSSL_PATH=${BUILD_PATH}/../openssl-1.1.1f

./configure --prefix=${BUILD_PATH}/_install 
	--with-cc=${CROSS_CC}gcc 
	--with-cpp=${CROSS_CC}g++ 
	--with-cc-opt=-pthread 
	--without-http_upstream_zone_module 
	--with-cc-opt="-D_GNU_SOURCE" 
    --with-http_ssl_module 
	--with-pcre=${PCRE_PATH} 
    --with-zlib=${ZLIB_PATH} 
	--with-openssl=${OPENSSL_PATH} 
	--with-openssl-opt="linux-generic32"
解决报错

执行上面的脚本 (build.sh) 会出现以下报错:

错误1:checking for C compiler ... found but is not working
checking for OS
 + Linux 2.6.32-696.el6.x86_64 x86_64
checking for C compiler ... found but is not working

./configure: error: C compiler arm-buildroot-linux-gnueabi-gcc is not found

解决方法:

修改 auto/cc/name 文件如下(注释掉 21 行)

 错误2:./configure: error: can not detect int size
checking for int size ...auto/types/sizeof: line 43: objs/autotest: cannot execute binary file
  bytes

./configure: error: can not detect int size

解决方法:

编辑 auto/types/sizeof 文件如下(注释掉 17 到 31 行,并修改 ngx_size=4,32位目标平台是4,64位的话是8),修改后如下:

修改完上面 2 处错误后重新执行 build.sh,出现下图即可:

Configuration summary
  + using PCRE library: /home/chengc/nginx/nginx-1.18.0/../pcre-8.45
  + using OpenSSL library: /home/chengc/nginx/nginx-1.18.0/../openssl-1.1.1f
  + using zlib library: /home/chengc/nginx/nginx-1.18.0/../zlib-1.2.11

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

接下来执行 make,不出意外的话就会出现以下错误:

错误3 :pcre-8.45/Makefile] 错误 77
configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details
make[1]: *** [/home/chengc/nginx/nginx-1.18.0/../pcre-8.45/Makefile] 错误 77
make[1]: Leaving directory `/home/chengc/nginx/nginx-1.18.0'
make: *** [build] 错误 2

解决方法1(推荐):修改 auto/options 文件中的 PCRE_CONF_OPT=--host=arm-buildroot-linux,然后重新执行 build.sh 脚本。

解决方法2: 修改 objs/Makefile,找到 pcre 部分,加上 --host

错误4:Failure!  build file wasn't produced.
Failure!  build file wasn't produced.
Please read INSTALL and associated NOTES files.  You may also have to look over
your available compiler tool chain or change your configuration.

target already defined - linux-x86_64 (offending arg: linux-generic32)
make[1]: *** [/home/chengc/nginx/nginx-1.18.0/../openssl-1.1.1f/.openssl/include/openssl/ssl.h] 错误 255
make[1]: Leaving directory `/home/chengc/nginx/nginx-1.18.0'

解决方法1(推荐):修改 auto/lib/openssl/make 文件如下,然后重新执行 build.sh 脚本。

​​​​​​​   

 解决方法2:修改 objs/Makefile,原文如下

修改 1242 行,将 ./config 改为 ./Configure CC=${CC} ,改后如下:

 错误5:'NGX_SYS_NERR' undeclared
src/os/unix/ngx_errno.c:58:11: error: 'NGX_SYS_NERR' undeclared (first use in this function)
     len = NGX_SYS_NERR * sizeof(ngx_str_t);
           ^
make[1]: *** [objs/src/os/unix/ngx_errno.o] 错误 1
make[1]: Leaving directory `/home/chengc/nginx/nginx-1.18.0'

解决方法:编辑 objs/ngx_auto_config.h,加入以下宏定义:

#ifndef NGX_SYS_NERR
#define NGX_SYS_NERR  132
#endif
错误6:undefined reference to `ngx_shm_alloc'
objs/src/core/ngx_cycle.o: In function `ngx_init_cycle':
/home/chengc/nginx/nginx-1.18.0/src/core/ngx_cycle.c:476: undefined reference to `ngx_shm_alloc'
/home/chengc/nginx/nginx-1.18.0/src/core/ngx_cycle.c:685: undefined reference to `ngx_shm_free'
/home/chengc/nginx/nginx-1.18.0/src/core/ngx_cycle.c:902: undefined reference to `ngx_shm_free'
objs/src/event/ngx_event.o: In function `ngx_event_module_init':
/home/chengc/nginx/nginx-1.18.0/src/event/ngx_event.c:551: undefined reference to `ngx_shm_alloc'
collect2: error: ld returned 1 exit status
make[1]: *** [objs/nginx] 错误 1
make[1]: Leaving directory `/home/chengc/nginx/nginx-1.18.0'

解决方法:编辑 objs/ngx_auto_config.h,加入以下宏定义:

#ifndef NGX_HAVE_SYSVSHM
#define NGX_HAVE_SYSVSHM 1
#endif

最后执行 make install

_install/
├── conf
│   ├── fastcgi.conf
│   ├── fastcgi.conf.default
│   ├── fastcgi_params
│   ├── fastcgi_params.default
│   ├── koi-utf
│   ├── koi-win
│   ├── mime.types
│   ├── mime.types.default
│   ├── nginx.conf
│   ├── nginx.conf.default
│   ├── scgi_params
│   ├── scgi_params.default
│   ├── uwsgi_params
│   ├── uwsgi_params.default
│   └── win-utf
├── html
│   ├── 50x.html
│   └── index.html
├── logs
└── sbin
    └── nginx

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/945859.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号