1.下载源码包 cd /opt/ rm -fr curl -o nginx.tar.gz http://nginx.org/download/nginx-1.20.1.tar.gz
2.编译安装 tar xf nginx.tar.gz cd nginx-1.20.1/ [root@localhost nginx-1.20.1]# ls auto CHANGES CHANGES.ru conf configure contrib html LICENSE man README src #1.配置编译参数 #这个软件给我们提供了很多功能,我们在编译的过程中可以自己选择哪些功能要,哪些功能不要,所有功能都要就是完整版,好多功能都不要就成了精简版,比如qq精简版,不知道大家听没听过。 ./configure --prefix=/usr/local/nginx --without-pcre --without-http_rewrite_module --without-http_gzip_module #禁掉了一些功能,有些功能都需要好多依赖包。--without就是去掉的意思。--prefix=/usr/local/nginx是指定软件的安装目录,目录不存在的话会自动创建,./是用相对路径来执行这个configure文件,用绝对路径也可以执行这个文件。这个指令执行之后,会自动检查各种依赖环境是否满足软件运行的要求,检查通过之后会生成一个叫做Makefile的文件。 [root@localhost nginx-1.20.1]# ls auto CHANGES.ru configure html Makefile objs src CHANGES conf contrib LICENSE man README
#多了两个文件Makefile和objs,刚才的指令主要是为了生成Makefile #2.编译 make #make会找当前目录中的Makefile文件来进行编译,这个编译过程一般是比较长的。1、看CPU性能2、软件功能复杂度 [root@localhost nginx-1.20.1]# ls auto CHANGES.ru configure html Makefile objs src CHANGES conf contrib LICENSE man README #编译之后看上去目录结构和之前一样,但是objs目录里面其实多了好多东西。 [root@localhost nginx-1.20.1]# ls objs/ autoconf.err nginx ngx_auto_config.h ngx_modules.c src Makefile nginx.8 ngx_auto_headers.h ngx_modules.o #其中nginx文件就是我们的二进制可执行的命令文件。它是可执行的程序了,比如我们查看一下它的版本 [root@1ocalhost nginx-1.20.1]#./objs/nginx-v nginx version:nginx/1.20.1 #到这里只是编译完了,还需要安装,其实安装就是将这个程序的某些文件放到对应的目录中去。其实我们在上面的编译参数中已经指定好了--prefix=/usr/1ocal/nginx,要安装到/usr/1ocal/nginx目录中去 #3.安装 make install #查看安装目录,这就是它这个软件安装的所有文件 [root@localhost nginx-1.20.1] #ls/usr/1ocal/nginx/ conf html logs sbin #这样看目录结构看若不太清晰,我们可以安装一下tree这个工具,来进行目录查看 [root@localhost nginx-1.20.1] # yum install tree -y #安装完tree之后,我们来看一下目录,看着就清晰多了,树状结构显示。 [root@localhost nginx-l.20.1] # tree /usr/local/nginx/ /usr/1ocal/nginx/ —conf #该软件的配置文件所在目录 3.运行 指令:/usr/local/nginx/sbin/nginx,没有配置环境变量,所以要用完整路径来运行 [root@1ocalhostnginx-1.20.1]# /usr/1ocal/nginx/sbin/nginx [root@localhost nginx-1.20.1] #看上去没什么效果,但是已经运行了 #可以通过浏览器访问这个nginx了,访问之前要关闭一下防火墙。 #关闭防火墙 systemctl stop firewalld #取消防火墙的开机自启 systemctl disable firewalld #使用浏览器访问http://<虚拟机的ip地址> http://192.168.61.132/就可以看到网站了。