nginx 中标麒麟arm编译过程
解压所有的依赖软件包,以及 Nginx 的源码包,所有源码包都位于同级目录下:
$ wget https://buildpack.oss-cn-shanghai.aliyuncs.com/static/r6d/nginx/nginx-compile-lib/pcre-8.44.tar.gz
$ tar xzf pcre-8.44.tar.gz
$ wget https://buildpack.oss-cn-shanghai.aliyuncs.com/static/r6d/nginx/nginx-compile-lib/zlib-1.2.11.tar.gz
$ tar xzf zlib-1.2.11.tar.gz
$ wget https://buildpack.oss-cn-shanghai.aliyuncs.com/static/r6d/nginx/nginx-compile-lib/openssl-1.1.1l.tar.gz
$ tar xzf openssl-1.1.1l.tar.gz
tar -xvf pcre-8.44.tar.gz
cd /opt/pcre-8.44
./configure
make
make install
报错:编译pcre 报错 error: Invalid C++ compiler or C++ compiler flags
![image.png](https://img-blog.csdnimg.cn/img_convert/e15525ef24a3ac3de02c5b07e16b1733.png#averageHue=#131313&clientId=uef73cfec-d558-4&crop=0&crop=0&crop=1&crop=1&from=paste&id=u811c3d4e&margin=[object Object]&name=image.png&originHeight=152&originWidth=746&originalType=url&ratio=1&rotation=0&showTitle=false&size=8357&status=done&style=none&taskId=uc899af9f-88e0-41c7-b13f-f1968126f4a&title=)
离线安装gcc-c++包
gcc-c++-7.3.0-20190804.h30.ky10.aarch64.rpm
libstdc++-devel-7.3.0-20190804.h30.ky10.aarch64.rpm
tar -xvf openssl-1.1.1l.tar.gz
cd /opt/openssl-1.1.1l
./config
make
make install
tar -xvf zlib-1.2.11.tar.gz
cd /opt/zlib-1.2.11
./config
make
make install
$ wget https://nginx.org/download/nginx-1.20.2.tar.gz
$ tar zxf nginx-1.20.2.tar.gz
$ cd nginx-1.20.2
执行 configure ,并指定静态编译参数:
$ ./configure
--prefix=/usr/local/nginx
--with-http_ssl_module
--with-openssl=../openssl-1.1.1l
--with-pcre=../pcre-8.44
--with-zlib=../zlib-1.2.11
开始执行编译:
$ make && make install
打包编译出来的 Nginx 目录即可:
$ tar czf nginx-1.20.2-arm64.tar.gz /usr/local/nginx
验证
查看编译后产生的可执行文件,会发现该二进制文件的编译类型为静态类型,这样的文件,可以在 arm64 架构下的任意 Linux 环境下运行。
$ file /usr/local/nginx/sbin/nginx
/usr/local/nginx/sbin/nginx: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, for GNU/Linux 3.7.0, BuildID[sha1]=66e5740a16bdfe6bc2f04c5371fd706ae7ca5395, not stripped
将编译好得文件nginx-1.18.0-arm64.tar.gz拷贝到需要使用得机器
解压
tar xzf nginx-1.18.0-arm64.tar.gz
配置服务 vi /etc/systemd/system/nginx.service
# /usr/lib/systemd/system
# systemd service file for Nginx Server forking server
#
[Unit]
Description=The nginx
After=network.target
[Service]
User=root
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/uar/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
重新加载配置
systemctl daemon-reload
重新服务
systemctl restart nginx.service
报错:make[1]: *** [/usr/local/pcre//Makefile] Error 127
解决:–with-pcre=DIR 是设置源码目录,而不是编译安装后的目录。改下,重新编译就好了。
![image.png](https://img-blog.csdnimg.cn/img_convert/b596f97fb2cb817f9a2c77dfd2bd7d37.png#averageHue=#20251e&clientId=uef73cfec-d558-4&crop=0&crop=0&crop=1&crop=1&from=paste&id=udf75bc9f&margin=[object Object]&name=image.png&originHeight=320&originWidth=800&originalType=url&ratio=1&rotation=0&showTitle=false&size=77534&status=done&style=none&taskId=ua2195a2a-84c0-40e4-9639-8006176d1ce&title=)
一、由于启动用户和nginx工作用户不一致所致
1.1查看nginx的启动用户,发现是nobody,而为是用root启动的
命令:ps aux | grep “nginx: worker process” | awk’{print $1}’
1.2将nginx.config的user改为和启动用户一致,
命令:vi conf/nginx.conf
二、缺少index.html或者index.php文件,就是配置文件中index index.html index.htm这行中的指定的文件。