一、在线版
1、下载安装包
wget http://nginx.org/download/nginx-1.21.6.tar.gz
2、解压
tar -zvxf nginx-1.21.6.tar.gz
3、预编译
cd nginx-1.21.6
./configure --prefix=/opt/nginx #注意:--prefix是指定安装目录(建议指定)
如果出现错误 ./configure: error: C compiler cc is not found
yum -y install gcc gcc-c++
如果出现错误 ./configure: error: the HTTP gzip module requires the zlib library.
yum -y install zlib-devel
如果出现错误 ./configure: error: the HTTP rewrite module requires the PCRE library.
yum -y install pcre-devel
如果出现错误 -bash: make: command not found
yum -y install make autoconf
4、编译
make
make install
5、安装完成测试
cd /opt/nginx/sbin
./nginx -t # 注意要加./
二、离线版
1、下载安装包
http://nginx.org/download,找到nginx-1.21.6.tar.gz版本
2、上传到centos文件夹里解压
tar -zvxf nginx-1.21.6.tar.gz
3、安装相关依赖
3.1、安装pcre
http://mirror.centos.org/centos/7/os/x86_64/Packages/pcre-devel-8.32-17.el7.x86_64.rpm/
上传后安装
rpm -ivh pcre-devel-8.32-17.el7.x86_64.rpm
3.2、安装zlib
http://mirror.centos.org/centos/7/os/x86_64/Packages/zlib-devel-1.2.7-18.el7.x86_64.rpm
上传后安装
rpm -ivh zlib-devel-1.2.7-18.el7.x86_64.rpm
还差什么可自行下载,地址:https://centos.pkgs.org/7/centos-x86_64/
3、预编译
cd nginx-1.21.6
./configure --prefix=/opt/nginx #注意:--prefix是指定安装目录(建议指定)
4、编译
make
make install
5、安装完成测试
cd /opt/nginx/sbin
./nginx -t # 注意要加./
记得要开防火墙端口才能访问80
firewall-cmd --permanent --add-port=80/tcp
service firewalld restart