腾讯云轻量服务器CentOS 7.6 64bit建站指南
结论先行
在腾讯云轻量服务器(CentOS 7.6 64bit)上建站的核心步骤包括:配置服务器环境(LNMP/LAMP)、上传网站文件、绑定域名并配置SSL证书。以下是详细操作流程。
一、服务器基础配置
1. 登录服务器
- 通过SSH工具(如PuTTY或Xshell)连接服务器:
ssh root@你的服务器IP - 输入密码后进入服务器终端。
2. 更新系统
yum update -y
3. 安装必要工具
yum install -y wget curl vim git
二、搭建网站环境(以LNMP为例)
1. 安装Nginx
yum install -y nginx
systemctl start nginx
systemctl enable nginx
- 验证Nginx:浏览器访问服务器IP,若显示Nginx欢迎页,说明安装成功。
2. 安装MySQL(MariaDB)
yum install -y mariadb-server mariadb
systemctl start mariadb
systemctl enable mariadb
- 初始化数据库:
mysql_secure_installation按提示设置root密码并移除测试数据库。
3. 安装PHP
yum install -y epel-release
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum install -y php72w php72w-fpm php72w-mysql
systemctl start php-fpm
systemctl enable php-fpm
- 验证PHP:创建测试文件
/var/www/html/info.php,内容为:<?php phpinfo(); ?>访问
http://服务器IP/info.php,显示PHP信息即成功。
三、上传网站文件
1. 创建网站目录
mkdir -p /var/www/yourdomain.com
chown -R nginx:nginx /var/www/yourdomain.com
2. 上传文件
- 通过FTP(如FileZilla)或SCP命令上传网站代码:
scp -r local_folder root@服务器IP:/var/www/yourdomain.com
四、配置Nginx虚拟主机
1. 创建配置文件
vim /etc/nginx/conf.d/yourdomain.com.conf
-
内容示例(替换
yourdomain.com为你的域名):server { listen 80; server_name yourdomain.com www.yourdomain.com; root /var/www/yourdomain.com; index index.php index.html; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ .php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } }
2. 重启Nginx
nginx -t # 测试配置
systemctl restart nginx
五、域名与SSL证书配置
1. 解析域名
- 在域名服务商处添加A记录,指向服务器IP。
2. 安装SSL证书(以Let’s Encrypt为例)
yum install -y certbot python2-certbot-nginx
certbot --nginx -d yourdomain.com -d www.yourdomain.com
- 按提示操作,证书会自动配置到Nginx。
六、防火墙与安全设置
1. 开放端口
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
2. 禁用root登录(可选)
vim /etc/ssh/sshd_config
- 修改
PermitRootLogin no,重启SSH:systemctl restart sshd
总结
- 核心步骤:安装LNMP环境 → 上传网站文件 → 配置域名与SSL。
- 关键命令:
yum install安装软件、nginx -t测试配置、certbot申请SSL证书。 - 注意事项:确保防火墙开放80/443端口,定期备份数据库和网站文件。
完成以上操作后,你的网站即可通过域名访问!如需进一步优化,可考虑配置CDN或数据库缓存。
ECLOUD博客