能否在单台AWS EC2 T1.micro实例的ElasticBeanstalk中部署多套独立WordPress?
Hey there! Let's walk through this step by step since you're new to AWS and want to set up multiple independent WordPress sites using Elastic Beanstalk (EB) with easy SSL management. I’ve helped folks with this exact setup before, so here’s a clear, actionable guide:
两种可行方案(推荐方案1给新手)
方案1:每个独立WordPress站点对应一个EB环境(最佳实践,运维简单)
This approach keeps each site completely isolated, and EB handles all the heavy lifting like EC2 provisioning, load balancing, and SSL setup—perfect if you want to avoid manual server tweaks.
步骤1:创建第一个WordPress EB环境
- Log into the AWS Console, navigate to Elastic Beanstalk, and click "Create Application".
- Name your application (e.g.,
CustomerWebsites) and select "Web server environment". - For the platform, pick the official WordPress image (AWS maintains this with pre-configured PHP/MySQL basics).
- Click "Create environment" and wait a few minutes for AWS to spin up all resources.
步骤2:配置自定义域名和SSL
- Once your environment is ready, go to its Configuration tab and find the Load balancer section (make sure you chose an Application Load Balancer during setup—this is required for easy SSL).
- Add an HTTPS listener (port 443):
- First, head to AWS Certificate Manager (ACM) to request a free SSL certificate for your custom domain (e.g.,
site1.com). Make sure the certificate is in the same AWS region as your EB environment. - Back in EB's load balancer settings, select your ACM certificate for the HTTPS listener and set it to forward traffic to HTTP port 80 (or HTTPS if you want end-to-end encryption).
- First, head to AWS Certificate Manager (ACM) to request a free SSL certificate for your custom domain (e.g.,
- Update your domain registrar's DNS settings: Point your domain's A record to your EB environment's load balancer DNS (or use Route 53 to create an alias record for cleaner setup).
步骤3:重复创建其他站点
- Simply repeat steps 1-2 for each customer's site. Each gets its own EB environment (you can group them under the same application or separate ones), with independent EC2 resources, SSL certificates, and domains.
方案2:单个EB环境运行多个WordPress站点(成本优化,需手动配置)
If you want to save on EC2 costs by sharing a single instance, you can set up virtual hosts on the EC2 instance managed by EB. This requires some Linux/Apache/Nginx knowledge, but it’s doable.
步骤1:创建基础PHP EB环境
- Instead of choosing the WordPress platform, select PHP (e.g., PHP 8.2 on Amazon Linux 2) when creating your EB environment. This gives you a blank PHP server to build on.
步骤2:连接到你的EC2实例
- From your EB environment's Instances tab, copy the EC2 instance ID, then navigate to the EC2 Console. Use SSH (or the EB CLI) to connect to the instance.
步骤3:配置Apache虚拟主机(Amazon Linux 2示例)
- Install missing dependencies if needed:
sudo yum install httpd php-mysqlnd mysql -y - Create directory structure for each site:
sudo mkdir -p /var/www/html/site1.com/public_html sudo mkdir -p /var/www/html/site2.com/public_html - 为每个站点下载并配置WordPress:
cd /var/www/html/site1.com/public_html sudo wget https://wordpress.org/latest.tar.gz sudo tar -xzf latest.tar.gz sudo mv wordpress/* . sudo rm -rf wordpress latest.tar.gz - 创建虚拟主机配置文件(每个站点重复此步骤):
# /etc/httpd/conf.d/site1.com.conf <VirtualHost *:80> ServerName site1.com ServerAlias www.site1.com DocumentRoot /var/www/html/site1.com/public_html ErrorLog /var/log/httpd/site1.com-error.log CustomLog /var/log/httpd/site1.com-access.log combined </VirtualHost> - 重启Apache使配置生效:
sudo systemctl restart httpd
步骤4:为所有站点配置SSL
- 在ACM申请多域名或通配符SSL证书(包含所有站点域名,例如
site1.com,site2.com)。 - 在EB的负载均衡器设置中,添加HTTPS监听器并选择你的ACM证书,将流量转发到HTTP 80端口。
- 更新所有站点的DNS记录,指向EB环境的负载均衡器地址。
步骤5:为每个站点配置独立数据库
- 使用AWS RDS创建MySQL/MariaDB实例(比EC2本地数据库更可靠)。
- 为每个站点创建专属数据库和用户:
CREATE DATABASE site1_db; CREATE USER 'site1_user'@'%' IDENTIFIED BY 'your_secure_password'; GRANT ALL PRIVILEGES ON site1_db.* TO 'site1_user'@'%'; FLUSH PRIVILEGES; - 访问每个站点的域名,运行WordPress安装向导,填入对应的数据库凭证。
关键成功提示
- SSL证书: 始终使用ACM获取免费、自动续期的证书。确保证书与EB环境在同一AWS区域,否则负载均衡器无法访问它。
- 数据库选择: RDS的额外成本很值得,它提供备份、高可用和自动更新功能。尽量避免在EC2实例上直接运行MySQL。
- 成本vs隔离性: 方案1成本更高,但能提供完全隔离(一个站点故障不会影响其他站点)。方案2节省资金,但需要更多手动维护工作。
内容的提问来源于stack exchange,提问作者Bhanu
相关产品推荐
相关产品推荐

