为子域启用 www 和非 www url

Pra*_*ngh -1 domain-name-system subdomain apache-2.2

我目前在 linode 上使用 apache 来托管我的网站。我使用了许多子域,每个子域只能通过非 www url 访问。www url 给出 503 错误。

但是,我希望可以从两种类型的 url 访问我的域。制作虚拟站点的典型配置如下所示:-

<VirtualHost *:80>
  # Admin email, Server Name (domain name), and any aliases
  ServerAdmin atiprashant@xyz.com
  ServerName  www.mobiles.xyz.com
  ServerAlias mobiles.xyz.com

  # Index file and Document Root (where the public files are located)
  DirectoryIndex index.html index.php
  DocumentRoot /home/prashant/public/xyz.com/public/mobiles

  # Log file locations
  LogLevel warn
  ErrorLog  /home/prashant/public/xyz.com/public/mobiles/log/error.log
  CustomLog /home/prashant/public/xyz.com/public/mobiles/log/access.log combined
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

linode 的 A/AAAA 记录如下所示:- 在此处输入图片说明

谁能告诉我我的方法有什么问题?如果我在提出疑问时不清楚,请发表评论。

谢谢 !

And*_*w B 5

DNS不会自动提供落在记录您已经定义了一个子域。(即,www.mobiles即使您已定义,也会返回 NXDOMAIN mobiles

有两种方法可以解决这个问题:

  1. 明确定义您希望人们请求的所有 DNS 记录。这是正常的方法。mobiles并且www.mobiles会有自己的 DNS 记录。
  2. 创建一个单独的通配符 DNS 记录,名为*.mobiles. 这将匹配低于 的记录mobiles。确保保留现有的mobilesDNS 记录,因为通配符与基本名称不匹配。