点击下载,此官网下载较慢,使用IDM或迅雷下载,不建议用CentOS-6
在安装nginx之前,要先安装pcre、openssl、zlib三个依赖,我本次安装版本号是下图所示,将下面四个拖放到centos7桌面
模块依赖性:
使用su及密码切换root权限,如果显示su:鉴定故障;使用sudo su及密码切换即可。
[admin123@localhost ~]$ su 密码: su: 鉴定故障 [admin123@localhost ~]$ sudo su [sudo] admin123 的密码: [root@localhost admin123]#
解压–>进入对应解压目录–>检查配置–>编译–>安装,openssl、zlib、nginx同样流程,也可以用yum安装,详细命令见8
[root@localhost Desktop]# tar -xvf pcre-8.21.tar.gz ---解压pcre压缩包 [root@localhost Desktop]# cd pcre-8.21/ ---进入解压后的目录 [root@localhost pcre-8.21]# ./configure ---检查配置 [root@localhost pcre-8.21]# make && make install ---编译并安装 [root@localhost pcre-8.21]# pcre-config --version ---查看是否成功安装
[root@localhost Desktop]# tar -xvf openssl-fips-2.0.2.tar.gz [root@localhost Desktop]# cd openssl-fips-2.0.2/ [root@localhost openssl-fips-2.0.2]# ./config [root@localhost openssl-fips-2.0.2]# make && make install
[root@localhost Desktop]# tar -xvf zlib-1.2.7.tar.gz [root@localhost Desktop]# cd zlib-1.2.7/ [root@localhost zlib-1.2.7]# ./configure [root@localhost zlib-1.2.7]# make && make install
nginx安装后路劲:/usr/local/nginx/sbin
[root@localhost Desktop]# tar nginx-1.12.2.tar.gz [root@localhost Desktop]# cd nginx-1.12.2/ [root@localhost nginx-1.12.2]# ./configure [root@localhost nginx-1.12.2]# make && make install [root@localhost sbin]# ls nginx [root@localhost sbin]# ./nginx ---启动NG
看下服务器ip和对应端口号为:localhost和80,访问CentOS,访问失败,原因为防火墙端口默认关闭,需要手动打开端口。
[root@localhost conf]# vim /usr/local/nginx/conf/nginx.conf
查看防火墙端口命令:firewall-cmd --list-all
[root@localhost conf]# firewall-cmd --list-all public (active) target: default icmp-block-inversion: no interfaces: ens32 sources: services: dhcpv6-client ssh ports: 80/tcp ---这里代表的是打开80端口,如果没有端口打开,这里会是空值 protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules:
设置开放的端口命令:sudo firewall-cmd --add-port=8001/tcp --permanent
开放8001端口
[root@localhost conf]# sudo firewall-cmd --add-port=8001/tcp --permanent success [root@localhost conf]# firewall-cmd --reload success [root@localhost conf]# firewall-cmd --list-all public (active) target: default icmp-block-inversion: no interfaces: ens32 sources: services: dhcpv6-client ssh ports: 80/tcp 8001/tcp protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules:
重启防火墙:firewall-cmd --reload
yum install gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel