0、安装环境与版本
[root@www myweb]# hostnamectl
Static hostname: www.long90.com
Icon name: computer-vm
Chassis: vm
Machine ID: b6c4900e4d474f0ab4f934696742044c
Boot ID: 62e0687c1bef4218b7b4cb3206226c30
Virtualization: vmware
Operating System: CentOS Linux 8
CPE OS Name: cpe:/o:centos:centos:8
Kernel: Linux 4.18.0-348.7.1.el8_5.x86_64
Architecture: x86-64
[root@www ~]# nginx22 -V
nginx version: nginx/1.22.1
built by gcc 8.5.0 20210514 (Red Hat 8.5.0-4) (GCC)
configure arguments: --prefix=/usr/local/nginx22
1、安装相关依赖
yum install gcc gcc-c++ automake pcre pcre-devel zlib zlib-devel openssl-devel make
2、下载nginx源码
官网地址:
http://nginx.org/en/download.html
# cd /opt/ngix22
# wget http://nginx.org/download/nginx-1.22.1.tar.gz
3、解压
tar -xzvf nginx-1.22.1.tar.gz
cd nginx-*
5、编译源码
# ./configure --prefix=/usr/local/nginx22
6、生成二进制安装程序,及安装
# make && make install
查看一下 /usr/local/nginx/ 看是否安装好,如下安装成功
# ls /usr/local/nginx22
conf html logs sbin
# ll
total 16
drwxr-xr-x 2 root root 4096 Jun 3 09:04 conf
drwxr-xr-x 2 root root 4096 Jun 3 09:04 html
drwxr-xr-x 2 root root 4096 Jun 3 09:04 logs
drwxr-xr-x 2 root root 4096 Jun 3 09:04 sbin
7、将 nginx 加入 systemctl 管理
vim /lib/systemd/system/nginx22.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/bin/kill -s HUP $MAINPID
ExecStop=/usr/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
更新系统守护程序
# systemctl daemon-reload
将 nginx 加入系统中
ln -s /usr/local/nginx22/sbin/nginx /usr/local/sbin/nginx22
8、启动服务与测试
启动服务
systemctl start nginx22
systemctl status nginx22
lsof -i :80