是的,一个阿里云服务器可以部署多个 WordPress 网站。这在实际应用中非常常见,尤其是在资源有限或者你希望节省成本的情况下。
下面是一个详细的部署方案,适用于 阿里云 ECS 服务器(如 CentOS、Ubuntu)+ Nginx/Apache + MySQL/MariaDB + PHP(LNMP 或 LAMP) 的环境:
✅ 前提条件
- 阿里云服务器(ECS),已安装 LNMP 或 LAMP 环境(推荐 LNMP)
- 已绑定两个域名,分别解析到该服务器 IP
- 服务器有足够资源(CPU、内存、磁盘空间)
🛠️ 部署步骤
步骤 1:准备 LNMP 环境(如果还未安装)
推荐使用 宝塔面板 或 lnmp.org 一键包 快速搭建环境。
以 lnmp.org 为例:
wget -c http://soft.vpser.net/lnmp/lnmp1.9-full.tar.gz
tar zxf lnmp1.9-full.tar.gz
cd lnmp1.9-full
./install.sh lnmp
安装完成后会包含:
- Nginx
- MySQL/MariaDB
- PHP(含 WordPress 所需模块)
步骤 2:创建两个数据库和用户
进入 MySQL 创建两个数据库:
CREATE DATABASE wp_site1;
CREATE DATABASE wp_site2;
CREATE USER 'wp_user1'@'localhost' IDENTIFIED BY 'your_password1';
CREATE USER 'wp_user2'@'localhost' IDENTIFIED BY 'your_password2';
GRANT ALL PRIVILEGES ON wp_site1.* TO 'wp_user1'@'localhost';
GRANT ALL PRIVILEGES ON wp_site2.* TO 'wp_user2'@'localhost';
FLUSH PRIVILEGES;
步骤 3:下载并配置两个 WordPress 站点
下载 WordPress:
cd /home/wwwroot
wget https://wordpress.org/latest.tar.gz
tar -zxvf latest.tar.gz
mv wordpress site1
cp -r site1 site2
现在你会有两个目录:
/home/wwwroot/site1/home/wwwroot/site2
分别对应两个站点。
步骤 4:配置 WordPress 的 wp-config.php
分别进入两个目录,编辑 wp-config.php 文件:
cd site1
cp wp-config-sample.php wp-config.php
nano wp-config.php
修改对应的数据库名、用户名和密码:
define('DB_NAME', 'wp_site1');
define('DB_USER', 'wp_user1');
define('DB_PASSWORD', 'your_password1');
另一个站点也做类似操作:
cd ../site2
cp wp-config-sample.php wp-config.php
nano wp-config.php
修改为:
define('DB_NAME', 'wp_site2');
define('DB_USER', 'wp_user2');
define('DB_PASSWORD', 'your_password2');
步骤 5:配置 Nginx 虚拟主机(两个域名)
在 /usr/local/nginx/conf/vhost/ 目录下创建两个配置文件:
示例:site1.conf
server {
listen 80;
server_name www.site1.com site1.com;
root /home/wwwroot/site1;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ .php$ {
include fastcgi_params;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
示例:site2.conf
server {
listen 80;
server_name www.site2.com site2.com;
root /home/wwwroot/site2;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ .php$ {
include fastcgi_params;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
保存后重启 Nginx:
lnmp nginx restart
步骤 6:访问并完成 WordPress 安装
浏览器访问:
- http://site1.com/wp-admin/install.php
- http://site2.com/wp-admin/install.php
按照提示完成各自站点的安装。
🧪 注意事项
-
权限问题:确保网站目录权限为
www:www,例如:chown -R www:www /home/wwwroot/site1 chown -R www:www /home/wwwroot/site2 -
伪静态规则:WordPress 需要启用伪静态,Nginx 中默认已经配置了。
-
PHP 版本兼容性:WordPress 推荐使用 PHP 7.4 ~ 8.2。
-
性能优化:若访问量大,可考虑使用缓存插件或 CDN。
✅ 总结
| 项目 | 内容 |
|---|---|
| 系统 | CentOS/Ubuntu |
| Web Server | Nginx |
| 数据库 | MySQL/MariaDB |
| PHP | PHP-FPM |
| 站点数量 | 2 个 WordPress |
| 域名 | 2 个不同域名 |
如果你需要我帮你生成完整的配置文件模板,或者用宝塔面板部署的方法,也可以告诉我!
CLOUD技术博