← 返回首页

Linux 服务器入门:从购买到部署

2026-04-15 · 运维

选型建议

对于个人项目或小团队,阿里云 ECS 性价比最高。我的选择:

安全组配置

开哪些端口要谨慎,多开一个就多一个攻击面:

端口 用途 建议来源IP
22 SSH 指定办公 IP
80/443 HTTP/HTTPS 0.0.0.0/0
3306 MySQL 127.0.0.1

Nginx 反向代理配置

外部访问通过 Nginx 转发到 Node.js 应用:

server {
    listen 80;
    server_name example.com;

    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

PM2 进程管理

用 PM2 保持 Node.js 进程常驻,自动重启、日志管理都很方便:

pm2 start app.js --name my-app
pm2 save
pm2 startup    # 开机自启

免费 SSL 证书

用 Certbot 申请 Let's Encrypt 免费证书,90 天自动续期:

yum install certbot python3-certbot-nginx -y
certbot --nginx -d example.com

小结

一台云服务器跑个人项目完全够用。关键把握好安全组、Nginx 反代和 PM2 这三样,基本能覆盖 90% 的部署需求。