centos7 nginx 安装启动卸载
Centos 下使用 yum 安装 nginx
1、添加源
默认情况 Centos7 中无 Nginx 的源,Nginx 官网提供了 Centos 的源地址。因此可以如下执行命令添加源:
sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
2、安装 Nginx
通过 yum search nginx
看看是否已经添加源成功。
如果成功则执行下列命令安装 Nginx。
sudo yum install -y nginx
启动 Nginx 并设置开机自动运行
启动 Nginx
sudo systemctl start nginx
开机自动运行
sudo systemctl enable nginx
浏览查看效果
在浏览器中输入您的服务器地址,注意需要打开 80 端口;nginx 默认是监听 80 端口的
如果您正在运行防火墙,请运行以下命令以允许 HTTP 和 HTTPS 通信:(如果防火墙关了,可直接跳过)
设置防火墙
允许 http 通信
sudo firewall-cmd --permanent --zone=public --add-service=http
允许 https 通信
sudo firewall-cmd --permanent --zone=public --add-service=https
重启防火墙
sudo firewall-cmd --reload
Nginx 卸载
停止 Nginx 软件
service nginx stop
删除 Nginx 的自动启动
chkconfig nginx off
从源头删除 Nginx
rm -rf /usr/sbin/nginx
rm -rf /etc/nginx
rm -rf /etc/init.d/nginx
再使用 yum 清理
yum remove nginx