最近在学习nginx使用,于是从Linux CentOS 7系统安装
首先分6个步骤,不出报错的情况下依次分开执行:
1 yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel (安装各种依赖)
2 wget http://nginx.org/download/nginx-1.20.1.tar.gz
3 tar zxvf nginx-1.20.1.tar.gz
4 cd nginx-1.20.1
5 ./configure --prefix=/usr/local/nginx
6 make&&make install
执行步骤1,在网络没问题的情况下,基本没有都能安装成功。
执行步骤2之前,记得先装下wget 执行命令 yum install -y wget
然后执行步骤2,在这里我遇到了一个报错“nginx.org xunable to resolve host address”,无法解析地址,DNS服务器错误。原因是:DNS服务器没有正确配置。解决方法:
1、打开文件/etc/resolv.conf在其中添加(先输入命令:“vi /etc/resolv.conf” 再输入“i”进入编辑模式,然后添加下面两行配置后输入“:wq”回车键,最后退出保存编辑):
nameserver 8.8.8.8
nameserver 8.8.4.4
2、然后重启网卡:使用命令: service network restart
再次执行步骤2,成功执行了。
执行步骤3,解压缩包成功。
执行步骤4,进入nginx-1.20.1目录成功。
执行步骤5,在配置信息的时候,出现一个报错 error:“nginx error: the HTTP rewrite module requires the PCRE library”
解决方法:
安装pcre-devel解决问题:执行命令:yum -y install pcre-devel;
还有可能出现错误提示:./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library. You can either disable the module by using
--without-http-cache option, or install the OpenSSL library into the system,
or build the OpenSSL library statically from the source with nginx by using
--with-http_ssl_module --with-openssl=<path> options.
解决办法:
安装openssl-devel解决问题:执行命令:yum -y install openssl openssl-devel;
还有可能出现的错误提示:error:c compiler cc is not found
原因是因为缺少 gcc-c++ 的包
解决办法:执行命令:yum -y install gcc-c++
执行步骤6,出现一个报错 make: *** No rule to make target `build', needed by `default'. Stop.
解决办法:
安装下面配置解决问题:执行命令:yum -y install make zlib-devel gcc-c++ libtool openssl openssl-devel 重新configure 执行命令:./configure
再次执行编译:make&&make install
最后安装成功!
1.启动nginx,无法在其他目录下,全局使用,如何解决?
-bash:nginx:未找到命令(command not found)说明nginx还没有配置到环境变量里,
1)配置环境变量,打开配置
vi /etc/profile
2)在文件最后加入一行代码(根据自己的安装目录填写)
export PATH=$PATH:/usr/local/nginx/sbin
3)刷新配置文件/etc/profile
source /etc/profile
2.启动nginx,在外部访问CentOS中部署应用时,需要关闭防火墙。
关闭防火墙命令:systemctl stop firewalld.service
开启防火墙:systemctl start firewalld.service
关闭开机自启动:systemctl disable firewalld.service
开启开机启动:systemctl enable firewalld.service