①安装wget命令
yum -y install wget
②下载nginx压缩包
wget http://nginx.org/download/nginx-1.16.1.tar.gz
③移动压缩包到指定目录,压缩包后面的路径可以自定义
mv nginx-1.16.1.tar.gz /home
④解压
[root@localhost ~]# cd /home
[root@localhost home]# tar -zxvf nginx-1.16.1.tar.gz
[root@localhost home]# ls
mysql mysqldata nginx-1.16.1 nginx-1.16.1.tar.gz
⑤重命名文件夹
[root@localhost home]# mv nginx-1.16.1 nginx
[root@localhost home]# ls
mysql mysqldata nginx nginx-1.16.1.tar.gz
⑥yum安装一些依赖库
yum install -y gcc pcre-devel openssl openssl-devel zlib-devel compat-libstdc++-33 libfreetype.i686 libXext.x86_64 pcre-devel
⑦编译,安装
[root@localhost home]# cd nginx
[root@localhost nginx]# ./configure
[root@localhost nginx]# make
[root@localhost nginx]# make install
⑧启动nginx
[root@localhost nginx]# cd /usr/local/nginx
[root@localhost nginx]# ls
conf html logs sbin
[root@localhost nginx]# cd sbin
[root@localhost sbin]# ./nginx
至此nginx已经安装启动完成,但是直接在浏览器输入服务器的ip地址却发现无法访问,因为我们还没有开启80端口,接下里是开启端口的命令。
开启端口时要保持防火墙开启!
①检查防火墙状态
[root@localhost sbin]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since 二 2020-01-14 09:52:10 CST; 2 months 19 days ago
Docs: man:firewalld(1)
Main PID: 719 (firewalld)
CGroup: /system.slice/firewalld.service
└─719 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid
1月 14 09:52:09 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
1月 14 09:52:10 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
如果防火墙没有开启,使用如下命令
systemctl start firewalld
②查看已开放的端口
[root@localhost sbin]# firewall-cmd --zone=public --list-port
3306/tcp
③添加端口并重启
[root@localhost sbin]# firewall-cmd --zone=public --add-port=80/tcp --permanent
success
[root@localhost sbin]# firewall-cmd --reload
success
[root@localhost sbin]# firewall-cmd --zone=public --list-port
3306/tcp 80/tcp
再次输入服务器ip会出现如下界面