为什么apache总是返回000-default而不是其他虚拟主机?

问题描述 投票:0回答:2

我尝试使用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

这是我自己的配置文件的内容:

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

我以root身份重启了apache(service apache2 reload)。但无论哪个域,唯一显示的页面是/ 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
apache virtual host
2个回答
0
投票

我终于找到了解决方案。在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表示“未修改”,因此页面未再次传输。清除浏览器缓存后,一切都按预期工作。

谢谢!


0
投票

按照以下步骤

  1. Sudo nano / tc tc /ぱ2 / x xt等/ h t t p d v h o sts。 Kon f
<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 website.localhost
  2. sudo apachectl重启 您可以替换ErrorLog和CustomeLog或检查错误enter code here / private / var / log / apache2 /
© www.soinside.com 2019 - 2024. All rights reserved.