无法使用Apache 2.4创建虚拟主机

时间:2014-01-08 22:03:35

标签: apache ubuntu vhosts

我正在尝试在新的Ubuntu 13.10安装上配置多个虚拟主机作为开发服务器。它只需要为自己服务。 Apache Server版本:Apache / 2.4.6(Ubuntu)

我看过http://httpd.apache.org/docs/2.4/vhosts/name-based.html https://help.ubuntu.com/13.04/serverguide/httpd.html和许多其他网站试图解决这个问题。

http://localhost正在运行但http://ncacaa.local未找到。我错过了什么? ping http://nacaa.local返回ping: unknown host http://ncacaa.local

以下是/etc/apache2/sites-available/ncacaa.conf的内容

<VirtualHost *:80>
    DocumentRoot "/var/www/vhosts/htdocs-ncacaa"
    ServerName ncacaa.local
    ErrorLog "/var/log/apache2/ncacaa.localhost-error.log"
    <Directory "/var/www/vhosts/htdocs-ncacaa">
       Order allow,deny
       Allow from all
       Require all granted
    </Directory>
</VirtualHost>

在a2ensite

创建的启用网站的目录中有一个符号链接

以下是000-default.conf文件中未注释的内容:

<VirtualHost *:80>
    ServerAdmin john@***.com
    DocumentRoot /var/www
    <Directory "/var/www">
            AllowOverride FileInfo
            Options Indexes FollowSymLinks
            Order allow,deny
            Allow from all
            Require all granted
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

以下是apache.conf文件中未注释的内容:

Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
LogLevel warn
<Directory />
    Options FollowSymLinks
    AllowOverride None
    Require all denied
</Directory>
<Directory /usr/share>
    AllowOverride None
    Require all granted
</Directory>
<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>
AccessFileName .htaccess
<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*
ServerName localhost:80

提前致谢!

1 个答案:

答案 0 :(得分:3)

配置中还需要一行才能启用虚拟主机:

NameVirtualHost *:80

虽然错误“ping http://nacaa.local返回ping:未知主机http://ncacaa.local”表示您的DNS无法解析。您需要添加到/ etc / hosts或设置dns。