openeuler22.03 LTS 源码编译安装nginx1.24.0

一、版本约束

软件的不同版本,在使用起来都有可能带来不可预知的影响,因此需要统一整理,固定下来,不允许轻易变更。

image-20241202233419932

  • Nginx开源版官网,点击右侧download可以看到各个版本的Nginx,其中Mainline是抢先的主干版本(版本号是奇数),Stable是稳定版(版本号是偶数)

  • 系统环境,软件版本

    • OpenEuler22.03 LTS SP4
    • nginx: 1.24.0

二、软件安装路径

  • 部署路径

    /home/application/nginx

  • 代码路径

    /home/application/nginx/html

  • 日志路径

    /home/application/nginx/logs

  • 配置文件路径

    /home/application/nginx/conf/nginx.conf 【主配置】

    /home/application/nginx/conf.d/*

  • ssl证书路径

    /home/application/nginx/cert

三、安装

3.1 下载

wget http://nginx.org/download/nginx-1.24.0.tar.gz

3.2 安装依赖

安装依赖包,NGINX是C语言写的,pcre-devel支持正则表达式,openssl 开启加密

 yum -y install gcc pcre-devel openssl-devel tar make

3.3 创建nginx用户

useradd -s /sbin/nologin nginx -M

3.4 指定安装目录

启用 HTTP/2 模块;启用 SSL 模块;启用 Stub Status 模块;启用4 层TCP/UDP 代理模块;启用 Gzip 静态模块
{.is-success}

/home/application/nginx

mkdir /home/application/nginx
tar -xf nginx-1.24.0.tar.gz
cd nginx-1.24.0
 ./configure --prefix=/home/application/nginx --user=nginx --group=nginx --with-http_v2_module --with-http_ssl_module --with-http_stub_status_module --with-stream --with-http_gzip_static_module  --pid-path=/home/application/nginx/nginx.pid

3.5 编译安装

make && make install

3.6 服务启动

3.6.1 编写 nginx.service 文件

vim /lib/systemd/system/nginx.service

[Unit]
Description=The NGINX HTTP and reverse proxy server
 
[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStart=/home/application/nginx/sbin/nginx
ExecReload=/home/application/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target

3.6.2 服务启动

systemctl daemon-reload
 
systemctl enable nginx
 
systemctl start nginx 
 
systemctl reload nginx  [重新加载配置文件,相当于 nginx -s reload]

四、平滑升级步骤

4.1 下载

wget https://nginx.org/download/nginx-1.26.2.tar.gz

4.2 解压

tar xf nginx-1.26.2.tar.gz

4.3 查看原先使用的模块

[root@nginx ~]# nginx -V
nginx version: nginx/1.18.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled

configure arguments: --prefix=/home/application/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-stream

4.4 编译安装

cd nginx-1.26.2
./configure --prefix=/home/application/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-stream
make

4.4 复制启动文件

mv /home/application/nginx/sbin/nginx /home/application/nginx/sbin/nginx-old

cp nginx-1.26.2/objs/nginx /home/application/nginx/sbin/

4.5 平滑升级

make upgrade

4.6 查看版本

/home/application/nginx/sbin/ -v

测试访问

image-20230627150752438