登录蓝速互联控制面板,选择香港节点的VPS并完成购买。
记录VPS公网IP、默认root账号与初始密码;建议同时上传SSH公钥以便免密登录。
在域名管理处准备好将要绑定的域名(后续需添加A记录指向VPSIP)。
在本地终端运行:ssh root@你的VPS_IP。
若使用密码登录,首次登录后立即修改root密码:passwd。
建议创建新用户并赋予sudo权限:adduser username && usermod -aG sudo username,然后使用公钥登录。
更新系统包并安装常用工具:
apt update && apt upgrade -y
apt install -y curl wget unzip git ufw nano
允许必要端口并启用ufw:
ufw allow OpenSSH && ufw allow 'Nginx Full' && ufw enable
安装并启用时区同步:apt install -y chrony && systemctl enable --now chrony
安装Nginx:apt install -y nginx && systemctl enable --now nginx
安装数据库:apt install -y mariadb-server && systemctl enable --now mariadb
安装PHP及常用扩展(以PHP 8.1为例):apt install -y php8.1-fpm php8.1-mysql php8.1-curl php8.1-gd php8.1-mbstring php8.1-xml php8.1-zip
运行mysql_secure_installation完成基本安全配置(设置root密码、移除匿名用户、禁远程root等)。
登录MariaDB创建数据库与用户:
mysql -u root -p
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY '强密码';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost'; FLUSH PRIVILEGES; EXIT;
切换到网站目录并下载:
mkdir -p /var/www/yourdomain.com && cd /var/www/yourdomain.com
wget https://wordpress.org/latest.tar.gz && tar xzvf latest.tar.gz --strip-components=1 && rm latest.tar.gz
复制配置样本:cp wp-config-sample.php wp-config.php,然后编辑数据库信息(DB_NAME、DB_USER、DB_PASSWORD、DB_HOST)。
将文件属主设置为www-data:chown -R www-data:www-data /var/www/yourdomain.com
目录权限755,文件权限644:find /var/www/yourdomain.com -type d -exec chmod 755 {} \; && find /var/www/yourdomain.com -type f -exec chmod 644 {} \;
确保php-fpm使用www-data用户(/etc/php/8.1/fpm/pool.d/www.conf)。
在/etc/nginx/sites-available/创建yourdomain.com文件,示例server块设置root指向/var/www/yourdomain.com,index index.php,location / 使用try_files,PHP请求通过fastcgi_pass unix:/run/php/php8.1-fpm.sock;
启用站点:ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/ && nginx -t && systemctl reload nginx
在域名注册商或DNS服务中添加A记录:@ 和 www 指向你的VPS公网IP;TTL可设为600以便快速生效。
使用ping yourdomain.com 或 dig +short yourdomain.com 检查解析是否到达VPSIP。
安装certbot并自动配置Nginx:apt install -y certbot python3-certbot-nginx
运行:certbot --nginx -d yourdomain.com -d www.yourdomain.com,按提示输入邮箱并同意条款。
设置自动续期:systemctl enable --now certbot.timer 或 crontab -e 添加renew命令。
安装fail2ban:apt install -y fail2ban 并启用SSH防护;定期更新:apt update && apt upgrade -y。
小内存VPS建议添加交换分区:fallocate -l 1G /swapfile && chmod 600 /swapfile && mkswap /swapfile && swapon /swapfile,并写入/etc/fstab。
可安装缓存(如Redis)或使用插件(WP Super Cache、W3 Total Cache)提升速度。
定期备份数据库与网站文件:mysqldump -u wpuser -p wordpress > /root/wordpress_$(date +%F).sql
使用rsync或第三方对象存储同步/var/www与数据库备份至外部服务器或云端,并测试恢复流程。
每月检查错误日志:/var/log/nginx/error.log 与 php-fpm 日志。
问:如何安全地生成并写入WP的AUTH_KEY等salt?
答:访问https://api.wordpress.org/secret-key/1.1/salt/ 获取一组随机salt,复制并替换wp-config.php中对应常量,或在命令行使用curl -s https://api.wordpress.org/secret-key/1.1/salt/ >> 临时文件,然后合并到wp-config.php。
问:WordPress加载速度慢,如何快速定位性能瓶颈?
答:先排查服务器资源(top, free -h, iotop, nginx日志),再检查PHP-FPM进程占用,启用缓存插件,使用静态资源压缩与CDN,检查DB慢查询并为常用字段加索引;必要时升级VPS规格或开启OPcache。
问:更新WordPress核心或插件前有哪些安全步骤?
答:先在测试环境或备份(文件+DB)后再操作;在更新前备份并记录当前版本;更新完后检查站点功能与错误日志;若出现问题,使用备份回滚或禁用主题/插件排查。