【问题标题】:Dynamic sub domain via Apache通过 Apache 的动态子域
【发布时间】:2014-03-29 04:50:37
【问题描述】:

给定一个用户名,我想“动态”创建一个子域。

我在

中阅读了答案

Create subdomains on the fly with .htaccess (PHP)

虽然它很好,但它不适合我,(我认为)因为我的服务器上有多个域(我在这里问了我最初的问题https://superuser.com/questions/720911/wildcard-subdomain-being-redirected-to-the-wrong-domain/720913?noredirect=1#comment923298_720913)。

我的设置是

  • Linode VPS
  • 阿帕奇
  • Ubuntu

我有多个域

  • abc.com
  • def.com

我希望我的动态子域位于第二个域(例如 x.def.com、y.def.com)。

所以我通过我的 DNS 管理器创建了一个通配符 DNS 条目。

但由于“abc.com”是配置的第一个域,它似乎以“x.def.com”的形式对任何子域进行“包罗万象”。

是否仍然可以在我的设置中实现动态子域创建?

我的虚拟主机设置如下

# in file /apache2/sites-available/abc.com 
<VirtualHost *:80>
  ServerName  www.abc.com

  DirectoryIndex index.php index.html
  DocumentRoot /home/website/public/abc.com/public/
</VirtualHost>

# in file /apache2/sites-available/def.com 
<VirtualHost *:80>
  ServerName  www.def.com
  ServerAlias *.def.com
  UseCanonicalName Off

  DirectoryIndex index.php index.html
  DocumentRoot /home/website/public/def.com/public/
</VirtualHost>

【问题讨论】:

  • 您能发布您当前的 VirtualHost 配置吗?您需要正确设置 ServerAlias 才能获取通配符子域。

标签: apache subdomain


【解决方案1】:

我觉得这个配置没问题。确保在主 apache 配置文件中设置了 NameVirtualHost *:80。如果您使用的是 Ubuntu,这可能在 ports.conf 中。

您可以使用apachectl -S 检查所有已配置的虚拟主机。如果设置正确,这应该包含您的通配符别名。

【讨论】:

    猜你喜欢
    • 2011-05-25
    • 2011-03-30
    • 1970-01-01
    • 2014-12-30
    • 2015-10-18
    • 1970-01-01
    • 2015-02-24
    • 1970-01-01
    • 2016-06-26
    相关资源
    最近更新 更多