尽管有多个虚拟主机,但所有流量都指向单个目录

时间:2014-06-21 19:29:16

标签: apache ubuntu virtualhost ubuntu-14.04

所有内容都指向我设置的子域名。

我的虚拟主机文件中必定存在错误,因为我非常确定DNS设置正确。

以下是主站点的虚拟主机文件:

# domain: mydomain.com
# public: /home/myusername/public/mydomain.com/

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

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

  <Directory /home/myusername/public/mydomain.com/public>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
  </Directory>

  # Log file locations
  LogLevel debug
  ErrorLog  /home/myusername/public/mydomain.com/log/error.log
  CustomLog /home/myusername/public/mydomain.com/log/access.log combined
</VirtualHost>

以下是子域的虚拟主机文件:

# domain: sub.mydomain.com
# public: /home/myusername/public/sub.mydomain.com/

<VirtualHost *:80>
  # Admin email, Server Name (domain name), and any aliases
  ServerAdmin webmaster@mydomain.com
  ServerName  sub.mydomain.com

  # Index file and Document Root (where the public files are located)
  DirectoryIndex index.html index.php
  DocumentRoot /home/myusername/public/sub.mydomain.com/public

  <Directory /home/myusername/public/sub.mydomain.com/public>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
  </Directory>

  # Log file locations
  LogLevel warn
  ErrorLog  /home/myusername/public/sub.mydomain.com/log/error.log
  CustomLog /home/myusername/public/sub.mydomain.com/log/access.log combined
</VirtualHost>

1 个答案:

答案 0 :(得分:3)

虚拟主机需要这个:
<VirtualHost sub.mydomain.com:80>