第一步:注册并购买云服务器
第二步:登录服务器与基础配置
ssh root@服务器公网IP
输入密码后进入服务器。
passwd
useradd -m 用户名 passwd 用户名 usermod -aG wheel 用户名 # CentOS usermod -aG sudo 用户名 # Ubuntu
第三步:安装必要环境
以搭建网站为例,需部署LAMP/LNMP环境:
yum update -y # CentOS apt update && apt upgrade -y # Ubuntu
yum install httpd -y # Apache(CentOS) systemctl start httpd && systemctl enable httpd
apt install nginx -y # Nginx(Ubuntu) systemctl start nginx && systemctl enable nginx
yum install mariadb-server mariadb -y # CentOS systemctl start mariadb && systemctl enable mariadb mysql_secure_installation # 运行安全配置脚本
yum install php php-mysqlnd php-fpm -y # CentOS systemctl start php-fpm && systemctl enable php-fpm
第四步:域名解析与备案
第五步:部署网站代码
/var/www/html/
(Apache)或/usr/share/nginx/html/
(Nginx)。 vi /etc/nginx/conf.d/your_domain.conf
输入以下内容:
server { listen 80; server_name your_domain.com; root /var/www/your_project; index index.php index.html; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ .php$ { include fastcgi_params; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } }
systemctl restart nginx
第六步:配置安全防护
firewall-cmd --permanent --add-service=http # 开放80端口 firewall-cmd --permanent --add-service=https # 开放443端口 firewall-cmd --reload
apt install certbot python3-certbot-nginx -y # Ubuntu certbot --nginx -d your_domain.com
vi /etc/ssh/sshd_config
修改PermitRootLogin
为no
,重启服务:
systemctl restart sshd
第七步:监控与维护
yum update
或apt update
修复破绽。 常见问题解答
systemctl status nginx
)、域名解析是否生效。 引用说明
本文参考阿里云官方文档《ECS新手入门》、腾讯云《LNMP环境搭建教程》、Let’s Encrypt官方指南。