在腾讯云服务器上使用 CentOS 系统新建一个网站(站点),通常包括以下几个步骤:
🧾 一、准备工作
- 已购买腾讯云服务器,并安装了 CentOS 系统。
- 已开放安全组端口(如:80、443)用于 HTTP/HTTPS 访问。
- 登录服务器:
ssh root@你的公网IP
🛠️ 二、安装 Web 服务环境
方法一:使用 Nginx + PHP + MySQL(LNMP)
1. 安装 EPEL 源(如果未安装)
yum install epel-release -y
2. 安安装 Nginx
yum install nginx -y
systemctl start nginx
systemctl enable nginx
3. 安装 MySQL(MariaDB)
yum install mariadb-server mariadb -y
systemctl start mariadb
systemctl enable mariadb
mysql_secure_installation
4. 安装 PHP 和常用模块
yum install php php-fpm php-mysqlnd php-gd php-xml php-mbstring -y
systemctl start php-fpm
systemctl enable php-fpm
📁 三、配置网站目录和 Nginx 虚拟主机
1. 创建网站根目录
mkdir -p /var/www/example.com/public_html
你可以上传网页文件到这个目录。
2. 创建 Nginx 配置文件
vim /etc/nginx/conf.d/example.com.conf
输入以下内容(根据实际域名修改):
server {
listen 80;
server_name example.com www.example.com;
root /var/www/example.com/public_html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location ~ .php$ {
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
3. 重启 Nginx
systemctl restart nginx
🔌 四、配置防火墙(Firewalld)
确保 HTTP/HTTPS 端口放行:
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
🌐 五、绑定域名(可选)
- 登录你的域名服务商后台(如腾讯云 DNS 或阿里云等)。
- 添加 A 记录,指向你的服务器公网 IP。
- 域名解析生效后,即可通过浏览器访问
http://example.com。
✅ 六、测试网站是否正常运行
在 /var/www/example.com/public_html 下创建一个测试页面:
echo "<?php phpinfo(); ?>" > /var/www/example.com/public_html/index.php
然后访问 http://example.com/index.php 查看是否显示 PHP 信息页。
🧹 七、后续建议
- 使用 Let’s Encrypt 配置 HTTPS(推荐 Certbot)。
- 使用宝塔面板(一键安装环境,适合新手)。
- 设置自动备份数据库和网站数据。
如果你需要搭建 WordPress、Typecho、Discuz 等 CMS,也可以继续告诉我,我可以提供对应的部署教程。
是否需要我帮你写一个完整的脚本或教你用宝塔面板快速建站?
CLOUD技术博