高级管理文档

配置通配符子域名

💡 云策文档标注

概述

本文档介绍了在基于域名的 WordPress 多站点网络中配置通配符子域名的方法,允许用户按需创建新站点而无需单独配置每个子域名。内容涵盖不同服务器环境下的具体配置步骤。

关键要点

  • 通配符子域名用于简化多站点网络中子域名的管理,避免逐个配置。
  • 配置涉及服务器设置(如 Apache 的 ServerAlias)和 DNS 记录(如 A 记录或 CName 记录)。
  • 文档提供了 Apache、CPanel、Plesk、DirectAdmin 和 Amazon Web Services 等环境的配置示例。
  • 在 AWS 中,需注意 IP 地址变化问题,建议使用 Elastic IP 地址,并处理 CName 限制。

注意事项

  • 某些域名注册商可能不支持通配符 CName 记录。
  • 使用 Amazon Route53 可以解决 CName 问题,但会产生额外费用。
  • 配置前请确保已创建 WordPress 多站点网络,具体方法可参考相关文档。
  • 如遇困难,建议联系您的网络托管服务商获取指导。

📄 原文内容

Wildcard subdomains are useful to allow end users of a domain-based WordPress multisite network to create new sites on demand. In this type of network each new site has its own subdomain, and the wildcard configuration means that those subdomains do not have to be configured individually. For information on how to create a multisite network, see: Create A Network.

This page contains some examples of how to configure wildcard subdomains in different circumstances. If you cannot determine how to set up wildcard subdomains on your particular web server, contact your webhost for directions.

Apache

In the httpd.conf file, or in the include file containing the VirtualHost section for your web account, add a line like this (if it is not already present):

ServerAlias *.example.com

Also create a wildcard DNS record like:

*.example.com A 192.0.2.1

CPanel

Make a sub-domain named “*” (wildcard) at your CPanel (*.example.com). Make sure to point this at the same folder location where your wp-config.php file is located.

Plesk

There are several steps that differ when setting up the server for wildcard subdomains on a server using Plesk Panel compared to a server using cPanel (or no control panel). This article Configuring Wildcard Subdomains for multi site under Plesk Control Panel details all the steps involved.

DirectAdmin

Click “User Panel” -> DNS Management -> add the following three entries using the three columns:

* A 192.0.2.1

Click “Admin Panel” (If you have no “admin panel” ask your host to do this) -> Custom Httpd -> yourdomain.com -> In the text input area, just paste and “save” precisely the following:

ServerAlias *.|DOMAIN|

If you ever need to un-do a custom Httpd: return here, delete text from input area, save.

Amazon Web Services

AWS instances are not assigned a permanent IP address by default. This means that a “server’s” IP address may change when it is rebooted. To resolve this issue, assign an Elastic IP Address to your server instance and use that IP address when configuring the A record with your registrar.

AWS Elastic Load Balancers cannot be assigned an elastic IP, therefore you must use a CName to give them a friendly URL. You cannot have a CName to a root URL. Therefore you must point the domain root (example.com) at a specific server instance with an Elastic IP address and create a wildcard CName (*.example.com) and point that at your Elastic Load Balancer. In your .htaccess, then just redirect all domain root traffic (example.com) to a specific sub-domain (www.example.com).

Notes:

  • Some registrars do not currently support wildcard CNames.
  • Amazon’s Route53 Domain Name Service eliminates the CName issue, but at an additional cost.