编译安装nginx-1.24.0
下载页面
目前(2023-08-03)最新稳定版本的nginx是1.24.0,这个版本是从1.23.4直接提升的稳定版本。
编译安装
需要编译工具
gcc
、make
依赖包
openssl:用于ssl
证书等相关功能
zlib:用于压缩等相关功能
pcre:正则匹配等相关功能。
一般nginx用静态编译,这几个依赖包只要下载源码即可,不需要另外安装,如果用系统自带的一般安装*-devel
包即可。
参数里面默认加了http2和stream支持
#!/bin/bash
# author : Jalright
# modify the version variable ,there you need !
nginx_version="1.24.0"
openssl_version="1.1.1v"
zlib_version="1.2.13"
pcre_version="8.45"
# the default install path , you can change it here
install_path="/usr/local/nginx"
# check file if exists , if not exit script.
function checkFile() {
if [ ! -f "$1" ]; then
echo "$1 is not exitst"
exit 1
fi
}
# install complie tools
yum -y install gcc gcc-c++ make wget tar
# temp dir
mkdir -p /tmp/make_nginx
cd /tmp/make_nginx
# download nginx
wget -c -t 0 -T 1200 http://nginx.org/download/nginx-${nginx_version}.tar.gz
checkFile nginx-${nginx_version}.tar.gz
# download openssl
wget -c -t 0 -T 1200 https://www.openssl.org/source/openssl-${openssl_version}.tar.gz
checkFile openssl-${openssl_version}.tar.gz
# download zlib for gizp
wget -c -t 0 -T 1200 http://zlib.net/zlib-${zlib_version}.tar.gz
checkFile zlib-${zlib_version}.tar.gz
# download pcre for regular expression
if [ ! -f "pcre-${pcre_version}.tar.gz" ]; then
wget -c -t 0 -T 1200 https://sourceforge.net/projects/pcre/files/pcre/${pcre_version}/pcre-${pcre_version}.tar.gz/download -O pcre-${pcre_version}.tar.gz
fi
checkFile pcre-${pcre_version}.tar.gz
# Don't need install the dependent packages , we juse need source code .
# When we compile nginx , it will compile with other dependent source code auto.
tar zxf openssl-${openssl_version}.tar.gz || echo "unpack openssl fail" && exit 1
tar zxf zlib-${zlib_version}.tar.gz
tar zxf pcre-${pcre_version}.tar.gz
tar zxf nginx-${nginx_version}.tar.gz
cd nginx-${nginx_version}
# default compile with http2 module 、ssl、status ... If you need other module , you can modify it here.
./configure --prefix=${install_path} --user=www --group=www --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-stream --with-http_stub_status_module --with-openssl=../openssl-${openssl_version} --with-pcre=../pcre-${pcre_version} --with-zlib=../zlib-${zlib_version} && exit 1
make
make install
# crete work user
useradd -M -s /sbin/nologin www
查看信息
/usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.24.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.1.1v 1 Aug 2023
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-stream --with-http_stub_status_module --with-openssl=../openssl-1.1.1v --with-pcre=../pcre-8.45 --with-zlib=../zlib-1.2.13
总结
启动
/usr/local/nginx/sbin/nginx
- 原文作者:Linux运维菜
- 原文链接:https://www.opcai.top/post/2023/2023-08/install_nginx-1.24.0/
- 版权声明:本作品采用进行许可,非商业转载请注明出处(作者,原文链接),商业转载请联系作者获得授权。