【CentOs/Nginx】把Nginx1.20.2在linux上run起来(详版)


【版本】

系统:CentOS Linux release 7.9.2009 (Core)

Nginx:1.20.2 (此为截至2022年3月4日的最新版)

【硬件】

T440p

下面是安装步骤

【安装必要组件】

#yum -y install pcre-devel openssl-devel

【安装gcc】

#yum install -y gcc g++ gcc-c++ make

如果没安装gcc会出现如下错误:

[root@localhost nginx-1.20.2]# ./configure
checking for OS
 + Linux 3.10.0-1160.el7.x86_64 x86_64
checking for C compiler ... not found

./configure: error: C compiler cc is not found

导致./configure不能运行。

出现也不必担心,按提示装上gcc即可。

【下载解压进目录】

#wget http://nginx.org/download/nginx-1.20.2.tar.gz
#tar -xvzf nginx-1.20.2.tar.gz
#cd nginx-1.20.2

【编译安装】

#./configure
#make && make install

【启动】

先看看nginx被安到哪里去了

[root@localhost nginx-1.20.2]# whereis nginx
nginx: /usr/local/nginx

然后进目录启动:

#cd /usr/local/nginx
#cd sbin
#./nginx

【验证】

打开浏览器,输入ip地址,就能看到nginx的欢迎画面了:

END