目标:初始化阿里云ECS,创建普通study用户,关闭root远程SSH登录,提升服务器安全。
1.阿里云控制台创建Rocky9实例,服务器公网IP:114.55.208.118。
2.MobaXterm以root登录服务器,创建普通用户study:
useradd study passwd study
作用:新建普通运维账号,日常操作尽量不使用root。
3.给study用户sudo管理员权限:
usermod -aG wheel study
4.修改ssh配置禁止root远程登录:
vi /etc/ssh/sshd_config # 设置 PermitRootLogin no systemctl restart sshd
5.测试:MobaXterm切换study账号登录,测试sudo命令。
目标:安装Nginx,部署静态网站,理解403权限报错原理。
1.安装Nginx软件:
dnf install nginx -y
2.启动nginx并设置开机自启:
systemctl start nginx systemctl enable nginx systemctl status nginx
3.防火墙放行http80端口:
firewall-cmd --add-service=http --permanent firewall-cmd --reload
4.创建网站目录,修改属主和权限:
mkdir -p /var/www/mysite chown -R study:study /var/www/mysite chmod 755 /var/www/mysite
5.编写Nginx站点配置文件 /etc/nginx/conf.d/mysite.conf
6.检查配置语法,平滑重载nginx:
nginx -t systemctl reload nginx
目标申请Let’s Encrypt免费SSL证书,配置http自动跳转https。
1.安装certbot工具:
dnf install certbot python3-certbot-nginx -y
2.阿里云域名解析添加A记录指向服务器公网IP 114.55.208.118,本地nslookup验证解析 fengqinqin.bond。
3.Nginx配置80端口,增加/.well-known/acme-challenge验证目录。
4.演练模拟申请证书(不真正下发证书)
certbot certonly --webroot -w /var/www/mysite -d fengqinqin.bond --dry-run
5.模拟成功后去掉--dry-run正式申请证书。
6.编写443 ssl服务块,填入证书全链、私钥路径。配置301跳转,访问http全部跳转https。
7.测试证书自动续期:
certbot renew --dry-run