> 文章列表 > centOS7.9安装nginx

centOS7.9安装nginx

centOS7.9安装nginx

此示例为安装nginx-1.20.1  (小版本无差别)

安装过程

sftp上传nginx-1.20.1.tar.gz文件到机器(在root目录下)

#cd /usr/local/nginx/sbin

#./nginx -V   (查看版本,如果已经有安装过的话会出现版本号)

切换到local目录下备份原先的nginx

#tar -zcvf nginx.tar.gz nginx/

#ps -ef|grep nginx   查看nginx进程

#kill -9 端口号    结束所有nginx进程

#rm -rf nginx    删除local下的旧nginx

#cd ..    切换到root目录下  解压新上传的nginx-1.20.1.tar.gz

#tar -zxvf nginx-1.20.1.tar.gz  

#cd nginx-1.20.1/   

#./configure --prefix=/usr/local/nginx       编译安装

#make

#make install

#cd /usr/local/nginx   

#cd conf

如果有旧的nginx.conf文件的话 上传上来覆盖一下修改,如果没有的话自己编辑配置

问题解决: 如果编译安装提示./configure: error: C compiler cc is not found

是因为缺少gcc环境,需要安装一下gcc

#yum -y install gcc-c++

如果make报错

还是因为缺少依赖

 

yum -y install gcc openssl openssl-devel pcre-devel zlib zlib-devel

因为之前安装过gcc依赖了, 这个命令里把gcc依赖去掉

yum -y install openssl openssl-devel pcre-devel zlib zlib-devel

执行:ESC---   :wq   保存nginx配置文件

#cd ../sbin/

启动nginx服务

#./nginx   启动nginx

#ps -ef|grep nginx    查看nginx进程

#./nginx -V    查看nginx版本应已经是1.20.1

#cd ~

#rm -rf nginx-1.20.1*    删除多余的无用文件