Apache显示默认页面VHOST页面

时间:2013-10-03 04:12:31

标签: apache webserver

我已经通过这样的虚拟主机添加了一些网站,我也指定了他们的文档路由。我在那里添加了所有内容,但出于某种原因,当我通过浏览器访问该站点时,Apache默认页面出现了。

<VirtualHost *:80>
    ServerAdmin admin@mydomain.com
    DocumentRoot "/var/www/html/mydomain/public_html"
    ServerName mydomain.com
    ServerAlias www.mydomain.com
    ErrorLog "/var/log/httpd/mydomain/error_log"
    CustomLog "/var/log/httpd/mydomain/access_log" common
</VirtualHost>

如果有人知道什么是错的,请告诉我!

2 个答案:

答案 0 :(得分:1)

您的ServerName是mydomain.com,但我假设您正在尝试连接到它,在您的浏览器上键入“localhost”。这样apache将使用默认的vhost而不是你的,这可能是在/etc/apache/sites-enabled/default上定义的。

您可以将mydomain.com设置为指向localhost。在Linux上编辑/etc/hosts文件,添加以下行:

127.0.0.1   mydomain.com

答案 1 :(得分:0)

假设您的虚拟主机的配置文件位于/etc/apache2/sites-available,则必须在/etc/apache2/sites-enabled上创建指向它的符号链接,如下所示:

ln -s /etc/apache2/sites-avaliable/mydomain.com /etc/apache2/sites-enabled/mydomain.com.conf

请注意,符号链接在sites-enabled的扩展名是.conf。就我而言,这是必需的,如主配置文件/etc/apache2/apache2.conf中所述:

# It is split into several files forming the configuration hierarchy outlined
# below, all located in the /etc/apache2/ directory:
#
#   /etc/apache2/
#   |-- apache2.conf
#   |   `--  ports.conf
#   |-- mods-enabled
#   |   |-- *.load
#   |   `-- *.conf
#   |-- conf-enabled
#   |   `-- *.conf
#   `-- sites-enabled
#       `-- *.conf

最后两行说明,仅加载扩展名为sites-enabled的{​​{1}}文件。