安装
这里以centos7.*为例。
添加Nginx存储库
sudo yum -y install epel-release
安装Nginx
现在Nginx存储库已经安装在您的服务器上,使用以下yum命令安装Nginx :
sudo yum -y install nginx
启动Nginx
Nginx不会自动启动.要运行Nginx,请输入:
sudo systemctl start nginx
查看安装位置:
ps -ef | grep nginx
设置nginx开机自启动
systemctl enable nginx.service
如果您正在运行防火墙,请运行以下命令以允许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
测试
输入地址:http://ip/
卸载
停止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