You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AWS环境下WordPress多站点服务器横向扩展方案咨询

Hey there! Let's walk through exactly how to scale your WordPress Multisite setup horizontally by adding a second identical server. I've handled this scenario a few times, so here's a step-by-step breakdown that covers all critical pieces:

1. Pre-Requisites & Prep Work

First, make sure you've got the basics covered to avoid mismatches down the line:

  • Ensure both servers are identical: same OS version, PHP version, web server (Apache/Nginx), WordPress core version, and all installed plugins/themes.
  • Full backup of your existing server: export the entire WordPress Multisite database, copy the wp-content directory (uploads, themes, plugins), and save config files like wp-config.php and .htaccess.
2. Set Up Shared Storage for wp-content

Since Multisite relies on shared media, themes, and plugins, you can't have separate wp-content folders on each server:

  • Deploy a shared storage solution (NFS or SMB work well) and migrate your existing wp-content directory to this shared location.
  • Mount the shared storage to /var/www/html/wp-content (or your WordPress root's wp-content path) on both servers.
  • Verify web server permissions: run sudo chown -R www-data:www-data /var/www/html/wp-content to ensure the server user can read/write to the shared folder.
3. Configure a Shared Database

WordPress Multisite needs a single shared database to sync sites, users, and settings across servers:

  • Export your existing Multisite database: mysqldump -u [db-username] -p [multisite-db-name] > multisite-backup.sql
  • Set up a database server (can be a standalone instance or one of your web servers, but standalone is better for scalability) and create a database user that's authorized to access from both web server IPs.
  • Import the backup to the shared database on your second server: mysql -u [db-username] -p [multisite-db-name] < multisite-backup.sql
  • Update wp-config.php on both servers to point to the shared database: ensure DB_HOST, DB_NAME, DB_USER, and DB_PASSWORD are identical, along with all Multisite-specific defines (like WP_ALLOW_MULTISITE, DOMAIN_CURRENT_SITE, and PATH_CURRENT_SITE).
4. Deploy a Load Balancer

You need a way to distribute traffic across both servers—here's how to handle it:

  • Choose a load balancer: Nginx (as a reverse proxy), HAProxy, or a cloud-native LB (like AWS ALB) all work.
  • Configure the LB to route traffic to both web server IPs, and set up health checks (e.g., pinging a static file or /wp-admin/install.php to verify server availability).
  • Fix session consistency: WordPress uses PHP sessions, so you have two options:
    • Preferred: Use shared session storage (Redis or Memcached). Install the Redis PHP extension, then add these lines to wp-config.php on both servers:
      define('WP_REDIS_HOST', 'your-redis-server-ip');
      define('WP_REDIS_PORT', 6379);
      define('SESSION_SAVE_HANDLER', 'redis');
      define('SESSION_SAVE_PATH', 'tcp://your-redis-server-ip:6379?database=0');
      
    • Sticky sessions (fallback): Configure your LB to route a user's traffic to the same server for their session, but note this reduces load-balancing efficiency.
5. Sync Web Server Configurations

Make sure both servers handle traffic the same way:

  • Copy your existing web server config (e.g., Apache's /etc/apache2/sites-available/wordpress.conf or Nginx's /etc/nginx/sites-available/wordpress.conf) to the second server.
  • Double-check paths and domain names in the config (since wp-content is shared, paths should match exactly).
  • Restart the web server on both instances: sudo systemctl restart apache2 or sudo systemctl restart nginx.
6. Test the Setup

Don't skip this step—verify everything works as expected:

  • Visit your site via the load balancer's domain to confirm it loads correctly.
  • Upload a test media file, then check the shared storage to ensure it's accessible from both servers.
  • Log into wp-admin, create a test subsite, and verify it appears when accessing the site via either server directly.
  • Test failover: Stop one web server and confirm traffic automatically routes to the remaining server without downtime.
7. Optional: Automate Configuration Sync

To keep both servers aligned long-term:

  • Use Git to track and sync config files like wp-config.php and web server settings.
  • Set up an automation tool like Ansible to push configuration changes to both servers at once, eliminating manual updates.

内容的提问来源于stack exchange,提问作者VIJAY THAKUR

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 04:04:24