添加Nginx源

CentOS7默认是没有Nginx源的,Nginx官方提供了添加源的命令:

1
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

安装Nginx

1
yum install -y nginx

启动Nginx

1
systemctl start nginx.service

设置开机自动运行

1
systemctl enable nginx.service

关闭防火墙

关闭

1
systemctl stop firewalld

查看状态

1
systemctl status  firewalld

测试

浏览器地址栏输入虚拟机IP,看到 Welcome to nginx! 就说明安装成功

卸载nginx

1
yum remove nginx

PS.

CentOS7关闭Nginx命令,nginx.service可简写成nginx

1
systemctl stop nginx.service

CentOS7启动Nginx命令

1
systemctl start nginx.service

CentOS7重启Nginx命令

1
systemctl restart nginx.service