一、进入官网http://nginx.org/en/download.html,找到最新linux版本,右键复制链接http://nginx.org/download/nginx-1.21.6.tar.gz
二、下载到/usr/local/src
[root@localhost ~]# cd /usr/local/src/ [root@localhost src]# wget http://nginx.org/download/nginx-1.21.6.tar.gz
三、解压安装包
[root@localhost src]# ls nginx-1.21.6.tar.gz [root@localhost src]# tar -zxvf nginx-1.21.6.tar.gz
四、进入nginx解压目录进行配置
[root@localhost src]# cd ./nginx-1.21.6 [root@localhost nginx-1.21.6]# ls auto CHANGES CHANGES.ru conf configure contrib html LICENSE man README src [root@localhost nginx-1.21.6]# ./configure --prefix=/usr/local/nginx
配置时报错,原因是缺少PCRE库
./configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using --without-http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library statically from the source with nginx by using --with-pcre=option.
解决方案:yum安装pcre-devel
[root@localhost nginx-1.21.6]# yum install pcre-devel
输入y进行确认
重新进行配置
[root@localhost nginx-1.21.6]# ./configure --prefix=/usr/local/nginx --with-pcre
发现还是报错,缺少zlib库
./configure: error: the HTTP gzip module requires the zlib library. You can either disable the module by using --without-http_gzip_module option, or install the zlib library into the system, or build the zlib library statically from the source with nginx by using --with-zlib=option. [root@localhost nginx-1.21.6]# Socket error Event: 32 Error: 10053. Connection closing...Socket close. Connection closed by foreign host. Disconnected from remote host(远程虚拟机) at 20:27:09. Type `help' to learn how to use Xshell prompt. [D:~]$
解决方案:yum安装zlib-devel
[root@localhost nginx-1.21.6]# yum install zlib-devel
输入y进行确认
进入src目录下载zlib源码包并解压出来
[root@localhost nginx-1.21.6]# cd .. [root@localhost src]# wget http://www.zlib.net/zlib-1.2.12.tar.gz [root@localhost src]# tar -zxvf zlib-1.2.12.tar.gz
重新进行配置
[root@localhost nginx-1.21.6]# ./configure --prefix=/usr/local/nginx
五、编译安装
[root@localhost nginx-1.21.6]# make [root@localhost nginx-1.21.6]# make install
查看有没有这个nginx目录
[root@localhost nginx-1.21.6]# ls /usr/local/nginx/ conf html logs sbin [root@localhost nginx-1.21.6]#
六、启动
[root@localhost nginx-1.21.6]# /usr/local/nginx/sbin/nginx [root@localhost init.d]# netstat -anput | grep nginx tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 21864/nginx: master
关闭防火墙,在浏览器上输入ip进行验证
[root@localhost ~]# systemctl stop firewalld



