山滚云

怎么在腾讯云服务器配置

分类: 腾讯云使用教程作者:时间:2025-10-19 10:22:36浏览量:8℃

​​一、快速部署方案(新手推荐)​​
​​方案1:使用腾讯云轻量应用服务器(最简单)​​
​​购买时选择应用镜像​​:
WordPress(博客/网站)
Typecho(轻量博客)
LAMP(Apache + PHP + MySQL)
Node.js 等
​​优势​​:
一键部署,无需手动配置环境
自动配置好域名、SSL证书等
​​方案2:使用宝塔面板(强烈推荐)​​
CentOS 安装命令
yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh

Ubuntu/Debian 安装命令
wget -O install.sh http://download.bt.cn/install/install-ubuntu_6.0.sh && sudo bash install.sh
​​安装后​​:
访问:http://你的服务器IP:8888
用户名/密码在安装完成后显示
​​二、手动配置 Web 环境​​
​​1. 安装 Nginx + PHP + MySQL(LEMP 环境)​​
更新系统(CentOS 7/8)
yum update -y

安装 EPEL 仓库(CentOS)
yum install epel-release -y

安装 Nginx
yum install nginx -y

启动并设置开机自启
systemctl start nginx
systemctl enable nginx

安装 PHP 7.4
yum install -y http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum-config-manager –enable remi-php74
yum install php php-fpm php-mysqlnd php-xml php-json php-gd php-mbstring -y

启动 PHP-FPM
systemctl start php-fpm
systemctl enable php-fpm
​​2. 安装 MySQL​​
下载 MySQL 8.0 仓库
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
rpm -Uvh mysql80-community-release-el7-3.noarch.rpm

安装 MySQL
yum install mysql-community-server -y

启动 MySQL
systemctl start mysqld
systemctl enable mysqld

获取临时密码
grep ‘temporary password’ /var/log/mysqld.log

安全配置
mysql_secure_installation
​​三、配置网站目录和权限​​
​​1. 创建网站目录​​
创建网站根目录
mkdir -p /var/www/html

创建测试文件
echo “<?php phpinfo(); ?>” > /var/www/html/info.php

设置权限
chown -R nginx:nginx /var/www/html
chmod -R 755 /var/www/html
​​2. 配置 Nginx 虚拟主机​​
编辑 Nginx 配置文件
vim /etc/nginx/conf.d/default.conf
​​配置文件内容​​:
server {
listen 80;
server_name your-domain.com www.your-domain.com;
root /var/www/html;
index index.php index.html index.htm;

location / {
try_files $uri $uri/ =404;
}

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

location ~ /\.ht {
deny all;
}
}
​​3. 测试并重启服务​​
测试 Nginx 配置
nginx -t

重启 Nginx
systemctl restart nginx
​​四、安全组配置(重要!)​​
在腾讯云控制台配置安全组:
​​必需开放的端口​​:
​​22​​:SSH 远程连接
​​80​​:HTTP 网站访问
​​443​​:HTTPS 加密访问
​​3306​​:MySQL 数据库(建议只开放给内网)
​​安全组配置步骤​​:
登录腾讯云控制台 → 云服务器 → 安全组
选择关联的安全组 → 编辑规则
添加入站规则:
类型:自定义
来源:0.0.0.0/0
协议端口:TCP:80,443,22
策略:允许
​​五、域名解析配置​​
​​1. 添加 A 记录​​
在域名管理后台(如腾讯云 DNSPod):
类型:A
主机记录:@ 或 www
记录值:你的服务器公网 IP
TTL:600
​​2. 验证解析​​
检查域名解析
nslookup your-domain.com
ping your-domain.com
​​六、SSL 证书配置(HTTPS)​​
​​1. 申请免费 SSL 证书​​
腾讯云控制台 → SSL 证书 → 申请免费证书
选择 TrustAsia 免费证书
填写域名信息,完成 DNS 验证
​​2. 下载并配置证书​​
创建证书目录
mkdir -p /etc/nginx/ssl/your-domain.com

上传证书文件
将 .crt 和 .key 文件上传到上述目录
​​3. 配置 HTTPS​​
编辑 Nginx 配置:
server {
listen 443 ssl;
server_name your-domain.com;

ssl_certificate /etc/nginx/ssl/your-domain.com/1_your-domain.com_bundle.crt;
ssl_certificate_key /etc/nginx/ssl/your-domain.com/2_your-domain.com.key;

ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;

其他配置同 HTTP
}

HTTP 重定向到 HTTPS
server {
listen 80;
server_name your-domain.com;
return 301 https://$server_name$request_uri;
}
​​七、网站程序部署​​
​​1. 上传网站文件​​
使用 SCP 上传(本地执行)
scp -r /本地网站目录/* root@服务器IP:/var/www/html/

或使用 SFTP 工具(FileZilla 等)
​​2. 数据库创建​​
登录 MySQL
mysql -u root -p

创建数据库和用户
CREATE DATABASE mywebsite;
CREATE USER ‘myuser’@’localhost’ IDENTIFIED BY ‘强密码’;
GRANT ALL PRIVILEGES ON mywebsite.* TO ‘myuser’@’localhost’;
FLUSH PRIVILEGES;
EXIT;
​​3. 安装常见网站程序​​
​​WordPress 示例​​:
cd /var/www/html
wget https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
mv wordpress/* .
chown -R nginx:nginx /var/www/html
​​八、性能优化和安全设置​​
​​1. 防火墙配置​​
开启防火墙(CentOS 7+)
systemctl start firewalld
systemctl enable firewalld

开放端口
firewall-cmd –permanent –add-service=http
firewall-cmd –permanent –add-service=https
firewall-cmd –permanent –add-service=ssh
firewall-cmd –reload
​​2. 禁用 root 远程登录​​
创建新用户
adduser myuser
passwd myuser

添加到 sudo 组
usermod -aG wheel myuser

修改 SSH 配置
vim /etc/ssh/sshd_config
修改以下配置:
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
​​九、验证网站运行​​
​​测试步骤​​:
​​访问 HTTP​​:http://你的域名
​​访问 HTTPS​​:https://你的域名
​​测试 PHP​​:https://你的域名/info.php
​​检查错误日志​​:tail -f /var/log/nginx/error.log
​​常用管理命令​​:
查看服务状态
systemctl status nginx
systemctl status php-fpm
systemctl status mysqld

重启服务
systemctl restart nginx

查看启动项
systemctl list-unit-files | grep enabled
​​十、备份和监控​​
​​1. 设置自动备份​​
创建备份脚本
vim /root/backup.sh
​​备份脚本内容​​:
!/bin/bash
备份网站文件和数据库
tar -czf /backup/website-$(date +%Y%m%d).tar.gz /var/www/html
mysqldump -u root -p密码 mywebsite > /backup/database-$(date +%Y%m%d).sql
​​2. 设置定时任务​​
编辑定时任务
crontab -e

添加每天凌晨备份
0 2 * * * /root/backup.sh
按照以上步骤配置完成后,你的腾讯云服务器就成功部署为功能完整的网站服务器了。建议新手从宝塔面板开始,熟练后再尝试手动配置。

【上一篇】
【下一篇】

相关推荐

关联代理购买腾讯云,可以享受
售前购买建议,官网+代理双重优惠,官网+代理双重售后服务!

蜗牛云是最高级腾讯云代理商,代理腾讯云所有代理商可以代销的产品,包括:腾讯云服务器,轻量应用服务器,腾讯云数据库,腾讯云邮箱,腾讯云安全,腾讯云CDN等腾讯云相关产品

业务范围:腾讯云代理,VPS推荐网,虚拟主机,云服务器  微信:ganshangwoniu    QQ:549233124    业务咨询热线:177-2050-9380

   Copyright © 2008-2025 腾讯云代理商版权所有   

QQ在线咨询
腾讯云代理商微信号