腾讯云轻量服务器CentOS 7.6 64bit建站指南
结论与核心步骤
在腾讯云轻量服务器(CentOS 7.6 64bit)上建站的核心流程包括:配置服务器环境(LNMP/LAMP)、上传网站文件、绑定域名和配置SSL证书。以下是详细步骤:
一、服务器基础配置
1. 登录服务器
- 通过SSH工具(如PuTTY或Xshell)连接服务器:
ssh root@服务器IP - 输入密码(首次登录需重置密码)。
2. 更新系统
yum update -y
二、安装Web环境(以LNMP为例)
1. 安装Nginx
yum install nginx -y
systemctl start nginx
systemctl enable nginx
- 验证安装:浏览器访问
http://服务器IP,看到Nginx欢迎页即成功。
2. 安装MySQL
yum install mariadb-server mariadb -y
systemctl start mariadb
systemctl enable mariadb
mysql_secure_installation # 运行安全配置脚本(设置root密码等)
3. 安装PHP
yum install epel-release -y
yum install php php-mysql php-fpm -y
systemctl start php-fpm
systemctl enable php-fpm
- 验证PHP:创建测试文件
/usr/share/nginx/html/info.php,内容为:<?php phpinfo(); ?>访问
http://服务器IP/info.php,显示PHP信息即成功。
三、上传网站文件
1. 准备网站目录
mkdir /var/www/your_site
chown -R nginx:nginx /var/www/your_site
2. 上传文件
- 使用FTP工具(如FileZilla)或SCP命令上传网站文件到
/var/www/your_site。
四、配置Nginx虚拟主机
1. 创建配置文件
vi /etc/nginx/conf.d/your_site.conf
-
示例配置(替换
your_domain.com为你的域名):server { listen 80; server_name your_domain.com; root /var/www/your_site; index index.php index.html; location / { try_files $uri $uri/ /index.php?$args; } 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. 绑定域名
- 在域名解析服务商(如腾讯云DNSPod)添加A记录,指向服务器IP。
2. 安装SSL证书(推荐Let’s Encrypt)
yum install certbot python2-certbot-nginx -y
certbot --nginx -d your_domain.com
- 按提示操作,证书会自动配置并续签。
六、防火墙与安全设置
1. 放行HTTP/HTTPS
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
2. 禁用root远程登录(可选)
vi /etc/ssh/sshd_config
修改 PermitRootLogin no,然后重启SSH:
systemctl restart sshd
七、测试与上线
- 访问你的域名,确认网站正常显示。
- 核心检查点:
- Nginx是否运行(
systemctl status nginx)。 - MySQL/PHP是否与网站程序兼容。
- SSL证书是否生效(浏览器显示🔒)。
- Nginx是否运行(
总结
关键步骤:安装LNMP环境 → 上传网站文件 → 配置Nginx → 绑定域名与SSL。
推荐工具:Certbot(免费SSL)、FileZilla(文件传输)、phpMyAdmin(数据库管理)。
按照以上流程,即可在腾讯云轻量服务器上快速搭建一个安全、高效的网站。
CLOUD云枢