Centos7 yum安装Nginx

sudo yum install yum-utils

To set up the yum repository, create the file named /etc/yum.repos.d/nginx.repo with the following contents:

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

By default, the repository for stable nginx packages is used. If you would like to use mainline nginx packages, run the following command:

注:默认安装包是稳定版,如果要按装开发版才执行下面的命令。

sudo yum-config-manager --enable nginx-mainline
如要关闭开发版可使用
sudo yum-config-manager --disable nginx-mainline

To install nginx, run the following command:

sudo yum install nginx

启动nginx服务
systemctl start nginx

设置nginx开机自启动

systemctl enable nginx.service

设置防火墙

允许http通信

sudo firewall-cmd --permanent --zone=public --add-service=http

允许https通信

sudo firewall-cmd --permanent --zone=public --add-service=https

重启防火墙

sudo firewall-cmd --reload

配置
默认的配置文件在 /etc/nginx 路径下,使用该配置已经可以正确地运行nginx;如需要自定义,修改其下的 nginx.conf 等文件即可。

 

卸载nginx

#停止Nginx服务
systemctl stop nginx.service

#删除Nginx的自动启动

systemctl disable nginx.service

#从源头删除Nginx

rm -rf /usr/sbin/nginx
rm -rf /etc/nginx
rm -rf /etc/init.d/nginx

#再使用yum清理

yum remove nginx

 

posted @ 2020-09-10 14:47  龙影123  阅读(250)  评论(0)    收藏  举报