当前位置: 首页 > article >正文

ubuntu24.04 编译安装 Nginx 1.26.2

文章目录

  • 写在前面
  • 安装步骤
    • 1. gcc 安装
    • 2. prce 安装
    • 3. zlib 安装
    • 4. openssl安装
    • 5. nginx 1.26.2(当前最新版) 安装
    • 6. 软连接
    • 7. 配置为系统服务
    • 8. 测试

写在前面

如题,本文将给出基于ubuntu24.04系统通过编译安装 Nginx 1.26.2 , 并将其配置为系统服务的完整方法。

安装步骤

1. gcc 安装

cd ~
apt update
apt install build-essential libpcre3-dev libssl-dev
gcc --version

2. prce 安装

版本查询

wget https://github.com/PCRE2Project/pcre2/releases/download/pcre2-10.44/pcre2-10.44.tar.gz
tar -zxvf pcre2-10.44.tar.gz
cd pcre2-10.44/
./configure
make
make install

3. zlib 安装

版本查询

cd ~
wget https://github.com/madler/zlib/releases/download/v1.3.1/zlib-1.3.1.tar.gz
tar -zxvf zlib-1.3.1.tar.gz
cd zlib-1.3.1/
./configure
make
make install

4. openssl安装

版本查询

cd ~
wget https://github.com/openssl/openssl/releases/download/openssl-3.3.1/openssl-3.3.1.tar.gz
tar -zxvf openssl-3.3.1.tar.gz
cd openssl-3.3.1/
./config --prefix=/usr
make

5. nginx 1.26.2(当前最新版) 安装

版本查询
编译模块查询

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

./configure \
--sbin-path=/usr/local/nginx/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
--pid-path=/usr/local/nginx/nginx.pid \
--http-log-path=/var/log/nginx/access.log \
--error-log-path=/var/log/nginx/error.log \
--with-pcre=../pcre2-10.44 \
--with-zlib=../zlib-1.3.1 \
--with-openssl=../openssl-3.3.1 \
--with-stream \
--with-stream_ssl_preread_module \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module

make
make install

6. 软连接

软连接用于解决可以执行 nginx -v 命令

ln -s /usr/local/nginx/nginx /usr/local/sbin/nginx

7. 配置为系统服务

执行命令vim /etc/systemd/system/nginx.service 在文件中写入以下内容并保存:

[Unit]
Description = nginx daemon

[Service]
ExecStart = /usr/local/nginx/nginx
ExecStop = /usr/local/nginx/nginx -s stop
ExecReload = /usr/local/nginx/nginx -s reload
Restart = always
Type = forking

[Install]
WantedBy = multi-user.target  

8. 测试

测试命令

root@it-nginx:~# systemctl daemon-reload
root@it-nginx:~# systemctl status nginx.service 
root@it-nginx:~# systemctl enable nginx.service
root@it-nginx:~# systemctl restart nginx.service
root@it-nginx:~# systemctl stop nginx.service   
root@it-nginx:~# nginx -V

命令执行记录

root@it-nginx:~# systemctl daemon-reload
root@it-nginx:~# systemctl status nginx.service 
● nginx.service - nginx daemon
     Loaded: loaded (/etc/systemd/system/nginx.service; enabled; preset: enabled)
     Active: active (running) since Thu 2024-08-29 06:04:10 UTC; 12min ago
   Main PID: 58062 (nginx)
      Tasks: 2 (limit: 9488)
     Memory: 1.6M (peak: 1.8M)
        CPU: 10ms
     CGroup: /system.slice/nginx.service
             ├─58062 "nginx: master process /usr/local/nginx/nginx"
             └─58063 "nginx: worker process"

Aug 29 06:04:10 it-nginx systemd[1]: Starting nginx.service - nginx daemon...
Aug 29 06:04:10 it-nginx systemd[1]: Started nginx.service - nginx daemon.
root@it-nginx:~# systemctl stop nginx.service 
root@it-nginx:~# systemctl status nginx.service 
○ nginx.service - nginx daemon
     Loaded: loaded (/etc/systemd/system/nginx.service; enabled; preset: enabled)
     Active: inactive (dead) since Thu 2024-08-29 06:16:49 UTC; 3s ago
   Duration: 12min 38.999s
    Process: 58175 ExecStop=/usr/local/nginx/nginx -s stop (code=exited, status=0/SUCCESS)
   Main PID: 58062 (code=exited, status=0/SUCCESS)
        CPU: 22ms

Aug 29 06:04:10 it-nginx systemd[1]: Starting nginx.service - nginx daemon...
Aug 29 06:04:10 it-nginx systemd[1]: Started nginx.service - nginx daemon.
Aug 29 06:16:49 it-nginx systemd[1]: Stopping nginx.service - nginx daemon...
Aug 29 06:16:49 it-nginx systemd[1]: nginx.service: Deactivated successfully.
Aug 29 06:16:49 it-nginx systemd[1]: Stopped nginx.service - nginx daemon.
root@it-nginx:~# systemctl start nginx.service 
root@it-nginx:~# systemctl status nginx.service 
● nginx.service - nginx daemon
     Loaded: loaded (/etc/systemd/system/nginx.service; enabled; preset: enabled)
     Active: active (running) since Thu 2024-08-29 06:17:01 UTC; 1s ago
    Process: 58186 ExecStart=/usr/local/nginx/nginx (code=exited, status=0/SUCCESS)
   Main PID: 58187 (nginx)
      Tasks: 2 (limit: 9488)
     Memory: 1.6M (peak: 1.9M)
        CPU: 11ms
     CGroup: /system.slice/nginx.service
             ├─58187 "nginx: master process /usr/local/nginx/nginx"
             └─58188 "nginx: worker process"

Aug 29 06:17:01 it-nginx systemd[1]: Starting nginx.service - nginx daemon...
Aug 29 06:17:01 it-nginx systemd[1]: Started nginx.service - nginx daemon.
root@it-nginx:~# nginx -V
nginx version: nginx/1.26.2
built by gcc 13.2.0 (Ubuntu 13.2.0-23ubuntu4) 
built with OpenSSL 3.3.1 4 Jun 2024
TLS SNI support enabled
configure arguments: --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --with-pcre=../pcre2-10.44 --with-zlib=../zlib-1.3.1 --with-openssl=../openssl-3.3.1 --with-stream --with-stream_ssl_preread_module --with-http_ssl_module --with-http_v2_module --with-http_realip_module

http://www.kler.cn/a/282720.html

相关文章:

  • 解决背景图因为图片路径中携带括号导致图片无法显示的问题
  • 浅层神经网络
  • C++清除所有输出【DEV-C++】所有编辑器通用 | 算法基础NO.1
  • Selective attention improves transformer详细解读
  • 从0开始学习--Day26--聚类算法
  • 数据结构--数组
  • 内六角圆柱头螺丝产品应用指南
  • C++ 设计模式——状态模式
  • 湖南的智榜样网络安全公司开的培训学校参加学习成为网络安全工程师
  • 世界上知名度最高的人物:颜廷利三言两语,震慑“中国哲学家”
  • RabbitMQ 集群与高可用性
  • 大学开学必备好物清单有哪些?开学必备清单大全,超详细版!
  • COMP9315-week2-lecture1
  • Python TensorFlow 实战指南
  • 【Unity输入】Input Manager 和 Input System对比
  • 详细解说数据库课程设计mysql
  • 前缀和2️⃣-二维前缀和
  • 先进制造aps专题二十五 openai的ai大模型设计也使用了aps用的并行遗传算法
  • Linux文件IO缓存
  • Linux(更新中~)
  • 【JVM原理】类加载机制
  • hadoop文件上传步骤
  • Golang | Leetcode Golang题解之第382题链表随机节点
  • 正则表达式pattern
  • 【CSS】选择器
  • GAN Inversion(GAN 反演)