大家好,我是程序员柏风,AI 最全的 Vibecoding 学习地图 http://coderoadmap.cn 作者。
Checkpoint: 基础设施
你将完成什么
- 购买云服务器(AWS EC2 / 阿里云 / 腾讯云)
- 配置域名解析(Route53 / DNSPod)
- 配置 HTTPS(Let's Encrypt / SSL 证书)
验收标准
- 服务器能 SSH 登录
- 域名能访问服务器
- HTTPS 证书有效
步骤
1. 购买云服务器
# 以 AWS EC2 为例
1. 登录 AWS Console → EC2 → Launch Instance
2. 选择 Amazon Linux 2 / Ubuntu
3. 选择 t2.micro(免费层)
4. 创建密钥对,下载 .pem 文件
5. 安全组开放 22(SSH)、80(HTTP)、443(HTTPS)
# SSH 连接
chmod 400 mykey.pem
ssh -i mykey.pem ec2-user@ec2-xx-xx-xx-xx.compute-1.amazonaws.com
# Ubuntu
ssh -i mykey.pem ubuntu@ec2-xx-xx-xx-xx.compute-1.amazonaws.com
2. 配置域名
# 购买域名(Namecheap / GoDaddy / 阿里云)
# 添加 A 记录指向服务器 IP
Type: A
Name: @
Value: 123.456.789.012
TTL: 600
# 等待 DNS 生效(通常 5-30 分钟)
dig yourdomain.com
nslookup yourdomain.com
3. 配置 HTTPS
# 安装 Certbot
sudo apt install certbot python3-certbot-nginx
# 获取证书
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
# 自动续期
sudo certbot renew --dry-run
4. Nginx 配置(HTTPS)
server {
listen 80;
server_name yourdomain.com;
return 301 https://$server_name$request_uri; # HTTP 重定向到 HTTPS
}
server {
listen 443 ssl http2;
server_name yourdomain.com;
ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
location / {
root /var/www/todo/dist;
try_files $uri /index.html;
}
location /api {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
常见卡点
- 安全组没开 80/443:AWS EC2 安全组需要手动添加规则。
- DNS 没生效:用
dig或nslookup检查,不要只看浏览器。 - Certbot 失败:确认域名已解析到服务器,Nginx 已启动。
下一步
完成本课后,进入「部署」阶段,把应用推送到服务器。