1.nginx安装
首先进入官网下载nginx安装包
将安装包放入centos7中
使用如下命令进行解压
[root@root]# tar -zxvf nginx-1.21.1
解压之后进入目录运行命令
[root@root]# ./configure
最后执行编译安装即可
[root@root]# make && make install
安装完成之后,会在/usr/local下生成nginx目录,该目录如下
sbin目录下就存放着nginx的操作文件,使用./nginx启动
通过命令查看启动状态
安装nginx遇到的问题
1、./configure: error: C compiler cc is not found
解决方法:安装gcc
[root@root]# yum -y install gcc
2、the HTTP rewrite module requires the PCRE library
解决方法:安装pcre-devel解决问题
[root@root]# yum -y install pcre-devel
3、the HTTP gzip module requires the zlib library.
解决方法:安装zlib-devel
[root@root]# yum -y install zlib-devel
通过ip:80访问nginx
首先打开防火墙80端口
[root@root]# systemctl status firewalld
该命令查看防火墙状态,若是active(running)便是打开状态
使用如下命令可以查看防火墙打开的端口信息
[root@root]# firewall-cmd --list-ports
防火墙开启端口访问
[root@root]# firewall-cmd --zone=public --add-port=80/tcp --permanent
命令含义: --zone #作用域 --add-port=80/tcp #添加端口,格式为:端口/通讯协议 --permanent #永久生效,没有此参数重启后失效
开启后需要重启防火墙才生效
[root@root]# firewall-cmd --reload
再执行 firewall-cmd --list-ports查看一次,则发现80端口已开启:
最后访问一下nginx地址