zh
在离岸VPS上托管WordPress:完整搭建指南
将WordPress托管在离岸VPS上,您可以完全控制服务器环境,享受更好的隐私保护,同时摆脱共享主机的各种限制。本指南以LEMP环境(Linux + Nginx + MySQL + PHP)为例,介绍从零开始在离岸VPS上搭建WordPress的全部步骤。
Need this done for your project?
We implement, you ship. Async, documented, done in days.
第一步:搭建LEMP环境
LEMP是Linux + Nginx + MySQL(MariaDB) + PHP的组合,是托管WordPress的高性能选择。
安装所有组件(Ubuntu 22.04):
apt update
apt install nginx mariadb-server php8.1-fpm php8.1-mysql php8.1-xml php8.1-curl php8.1-gd php8.1-mbstring php8.1-zip -y
启动并启用所有服务:
systemctl enable --now nginx mariadb php8.1-fpm
安全初始化MySQL:
mysql_secure_installation
按提示:设置root密码、删除匿名用户、禁止root远程登录、删除测试数据库。
创建WordPress专用数据库和用户:
mysql -u root -p
CREATE DATABASE wordpress_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY '强密码请替换此处';
GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wp_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
第二步:下载和配置WordPress
下载最新版WordPress并解压到网站目录:
cd /tmp
wget https://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
mv wordpress /var/www/example.com
chown -R www-data:www-data /var/www/example.com
chmod -R 755 /var/www/example.com
复制并编辑WordPress配置文件:
cd /var/www/example.com
cp wp-config-sample.php wp-config.php
nano wp-config.php
修改数据库配置部分:
define('DB_NAME', 'wordpress_db');
define('DB_USER', 'wp_user');
define('DB_PASSWORD', '您设置的强密码');
define('DB_HOST', 'localhost');
同时访问 https://api.wordpress.org/secret-key/1.1/salt/ 生成安全密钥并替换配置文件中对应部分。
第三步:配置Nginx和HTTPS
为WordPress创建Nginx配置文件:
nano /etc/nginx/sites-available/wordpress
填入WordPress专用Nginx配置,关键点包括:启用PHP-FPM处理、配置固定链接重写规则、拒绝访问敏感文件。
核心配置片段:
server {
listen 80;
server_name example.com www.example.com;
root /var/www/example.com;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ .php$ {
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /. { deny all; }
}
启用配置并申请HTTPS证书:
ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
nginx -t && systemctl reload nginx
certbot --nginx -d example.com -d www.example.com
第四步:WordPress性能和安全优化
安装完成后进行以下优化:
性能优化:
- 安装缓存插件(推荐W3 Total Cache或WP Super Cache)
- 启用Nginx FastCGI缓存(进阶配置)
- 使用CDN加速静态资源
安全加固:
- 修改默认登录路径(wp-admin),使用WPS Hide Login插件
- 安装Wordfence安全插件启用防火墙和登录保护
- 在wp-config.php中禁止文件编辑:define('DISALLOW_FILE_EDIT', true);
- 定期备份(推荐UpdraftPlus插件,配合离岸存储)
- 设置强密码策略,启用双因素认证
AnubizHost离岸VPS托管WordPress的优势在于:无内容审查、隐私保护到位、不受地缘政治干扰,同时提供充足的存储和带宽支持高流量网站。
Related Services
Why Anubiz Host
100% async — no calls, no meetings
Delivered in days, not weeks
Full documentation included
Production-grade from day one
Security-first approach
Post-delivery support included
Ready to get started?
Skip the research. Tell us what you need, and we'll scope it, implement it, and hand it back — fully documented and production-ready.