安装 yum install nginx
启动 service nginx start
停止 service nginx stop
重载 service nginx reload
systemctl命令:
systemctl list-unit-files|grep nginx 查找
systemctl start nginx //启动服务
systemctl stop nginx //停止服务
systemctl restart nginx //重启服务
systemctl status nginx //查看服务当前状态
systemctl enable nginx //设置开机自启动
systemctl disable nginx //停止开机自启动
安装epel
yum install epel-release -y
yum -y remove epel-release
yum clean all && yum makecache
cd /etc/yum.repos.d/
sudo yum intsall nginx
sudo systemctl start nginx 启动服务
sudo firewall-cmd --permanent --zone=public --add-service=http 允许http通信
sudo firewall-cmd --permanent --zone=public --add-service=https 允许https通信
sudo firewall-cmd --reload 重新加载配置
在 /etc/nginx/conf.d 目录中新建一个my.conf文件,在此之前先将nginx.conf 配置文件中的server节点注释掉
server{
listen 80;
server_name www.test.com;
root /wwwroot/demo;
index index.html index.htm;
}
/wwwroot/demo
index.html内容
<html>
<head>
<meta charset="UTF-8">
<title>这是一个测试页面</title>
</head>
<body>
<h1>测试页面</h1>
</body>
</html>
sudo nginx -s reload 重新加载配置文件
sudo systemctl restart nginx 重启nginx
修改hosts 文件配置自定义域名
windows位置:C:WindowsSystem32driversetchosts
192.168.3.89 www.test.com
刷新 dns:ipconfig /flushdns
linux位置 /etc/hosts
//访问站点403错误原因:SELinux设置为开启状态(enabled)的原因
将SELINUX=enforcing 修改为 SELINUX=disabled 状态
vim /etc/selinux/config
#SELINUX=enforcing
SELINUX=disabled
重启生效:reboot
sudo setenforce 0