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

标签 apache ubuntu vhosts

我正在尝试在新的 Ubuntu 13.10 安装上配置多个虚拟主机作为开发服务器。它只需要为自己服务。
Apache 服务器版本: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 创建的 sites-enabled 目录中有一个指向它的符号链接(symbolic link)

以下是 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

提前致谢!

最佳答案

配置中还需要一行来打开虚拟主机:

NameVirtualHost *:80

虽然错误“ping http://nacaa.local 返回 ping: unknown host http://ncacaa.local”意味着您的 dns 没有解析。您需要添加到/etc/hosts 或设置 dns。

关于apache - 无法使用 Apache 2.4 创建虚拟主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21007543/

相关文章:

apache - Fail2ban with apache filter for 40*-hits

nginx - 每个域和子域的 Plesk nginx 配置

nginx - 检查cookie是否不包含指定的内容NGINX

apache - 站点文件夹的 www-data 和组读取问题

c - 没有这样的文件或包含头文件 C 的目录错误

linux - 在 Ubuntu 11.10 中通过命令行重启 VPN

php - file-exists 检查 php 的 auto_prepend_file

apache - 为什么显示我的PHP源代码?

java - 将 RTF 文件转换为 DOC

apache - 许多 php-fpm : pool www processes running but Apache isn't