龙空技术网

CentOS 上编译安装nginx-1.24.0

linux运维菜 111

前言:

现在各位老铁们对“centos重装nginx”大致比较看重,朋友们都想要剖析一些“centos重装nginx”的相关内容。那么小编同时在网络上网罗了一些有关“centos重装nginx””的相关文章,希望朋友们能喜欢,咱们快快来学习一下吧!

目前(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 hereinstall_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 toolsyum -y install gcc gcc-c++ make wget tar# temp dirmkdir -p /tmp/make_nginxcd /tmp/make_nginx# download nginxwget -c -t 0 -T 1200 {nginx_version}.tar.gzcheckFile nginx-${nginx_version}.tar.gz# download opensslwget -c -t 0 -T 1200 {openssl_version}.tar.gzcheckFile openssl-${openssl_version}.tar.gz# download zlib for gizpwget -c -t 0 -T 1200 {zlib_version}.tar.gzcheckFile zlib-${zlib_version}.tar.gz# download pcre for regular expressionif [ ! -f "pcre-${pcre_version}.tar.gz" ]; then    wget -c -t 0 -T 1200 {pcre_version}/pcre-${pcre_version}.tar.gz/download -O pcre-${pcre_version}.tar.gz ficheckFile 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 1tar zxf zlib-${zlib_version}.tar.gztar zxf pcre-${pcre_version}.tar.gz tar zxf nginx-${nginx_version}.tar.gzcd 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 1makemake install# crete work useruseradd -M -s /sbin/nologin www

查看信息

/usr/local/nginx/sbin/nginx  -Vnginx version: nginx/1.24.0built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)built with OpenSSL 1.1.1v  1 Aug 2023TLS SNI support enabledconfigure 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

标签: #centos重装nginx #centos编译