【问题标题】:Why does apache always returns 000-default instead of other virtual hosts?为什么 apache 总是返回 000-default 而不是其他虚拟主机?
【发布时间】:2016-07-15 15:45:33
【问题描述】:

我尝试在一台服务器上设置两个域,使用 apache 和虚拟主机。我为每个域创建了一个 conf 文件,但似乎 apache 总是使用 000-default 而不是我自己的 conf 文件。

这是我的目录结构:

/var/www# ls -al
-rw-r--r-- 1 www-data www-data  236 Mär 11 16:21 .htaccess
-rw-r--r-- 1 root     root       43 Mär 28 05:22 index.html
drwxr-xr-x 5 www-data www-data 4096 Mär 28 05:02 domain-1.de
drwxr-xr-x 2 www-data www-data 4096 Mär 28 05:13 domain-2.de

我想我已经启用了两个域:

ls -l /etc/apache2/sites-enabled/
lrwxrwxrwx 1 root root 26 Mär  7 09:18 000-default -> ../sites-available/default
lrwxrwxrwx 1 root root 38 Mär 28 03:56 domain-1.de -> ../sites-available/domain-1.de
lrwxrwxrwx 1 root root 39 Mär 28 03:56 domain-2.de -> ../sites-available/domain-2.de

这是我自己的conf文件的内容:

<VirtualHost *:80>
    ServerName domain-2.de
    ServerAlias www.domain-2.de
    DocumentRoot /var/www/domain-2.de
</VirtualHost>

我以 root 身份重新启动了 apache(服务 apache2 重新加载)。 但无论是哪个域,唯一显示的页面是 /var/www 中的 index.html。

这是/var/log/apache2/error.log的内容:

[Mon Mar 28 07:15:02 2016] [notice] Graceful restart requested, doing restart
[Mon Mar 28 07:15:02 2016] [notice] Apache/2.2.22 (Debian) PHP/5.4.45-0+deb7u2 configured -- resuming normal operations

【问题讨论】:

  • service apache2 restart 会有所不同。也许也可以尝试 sudo
  • 请添加您要求的网址。
  • 这个“more domain-2.de”在里面做什么?
  • @Sarcoma 我重新启动了 apache,但这并没有帮助。
  • 在基于 debian 的发行版中默认配置的正常行为是只考虑那些文件夹中的那些文件,这些文件以 *.conf 结尾。其他一切都被忽略。可能是您的 http 服务器根本不使用您创建的那些文件。看看你的 apache 配置中的 IncludeOptional 配置语句。

标签: apache virtual host


【解决方案1】:

按照以下步骤进行

  1. sudo nano /etc/apache2/extra/httpd-vhosts.conf

<VirtualHost *:80>
  # Admin email, Server Name (domain name), and any aliases
  ServerName  website.localhost
  ServerAlias www.website.localhost

  # Index file and Document Root (where the public files are located)
  DirectoryIndex index.html index.php
  DocumentRoot "/Users/Username/Sites/website"

  # Log file locations
  LogLevel warn

  ErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log"
  CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log" common

    <Directory /Users/Username/Sites/website>
        Options Includes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
         Require all granted
    </Directory>
</VirtualHost>
  1. 允许来自 Apache 配置文件 httpd.conf 的 vhosts 配置

    sudo nano /etc/apache2/httpd.conf

搜索“vhosts”并取消注释包含行 虚拟主机 包括 /private/etc/apache2/extra/httpd-vhosts.conf 这将允许使用 httpenter code hered-vhosts.conf 文件,打开此文件以添加到 vhost。

  1. sudo nano /etc/hosts

    127.0.0.1 网站.localhost

  2. sudo apachectl 重启

    您可以替换ErrorLog和CustomeLog或检查错误enter code here/private/var/log/apache2/

【讨论】:

    【解决方案2】:

    我终于找到了解决办法。 在 other_vhosts_access.log 中有多个条目,如

    [28/Mar/2016:09:50:11 -0500] "GET /index.html HTTP/1.1" 304 212 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
    

    Http 返回码 304 表示“未修改”,因此页面没有再次传输。清除浏览器缓存后,一切正常。

    谢谢!

    【讨论】:

    • 永远不会从缓存版本的回复中向另一个域提供请求!很奇怪。
    猜你喜欢
    • 2016-10-12
    • 1970-01-01
    • 2018-07-08
    • 2019-02-21
    • 2019-11-14
    • 1970-01-01
    • 2010-12-16
    • 2012-10-13
    相关资源
    最近更新 更多