通过Apache动态子域

时间:2014-02-26 11:32:07

标签: apache subdomain

鉴于用户名,我想“动态”创建子域名。

我在

中阅读了答案

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
  • 的Apache
  • 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>

1 个答案:

答案 0 :(得分:0)

该配置对我来说没问题。确保在主apache配置文件中设置了NameVirtualHost *:80。如果您正在使用Ubuntu,则可能在ports.conf中。

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