尽管配置正确,但NamedVirtiaulHost仍无法正常工作

时间:2015-08-22 21:44:07

标签: apache .htaccess ubuntu

Ubuntu 14.04服务器,Apache2。我在domain.tld下有一个Prestashop网店,工作正常。 我现在想在我的服务上安装webmail,所以我添加了一个指向/ var / www / webmail的虚拟主机。

但是,当我转到webmail.domain.tld时,我总是会重定向到domain.tld。

我经常使用Google,这一切看起来都不错。这是DUMP_VHOSTS的输出

root@ubuntu-1404:/etc/apache2# apachectl -t -D DUMP_VHOSTS
VirtualHost configuration:
*:443                  is a NameVirtualHost
         default server www.domain.tld (/etc/apache2/sites-enabled/domain.tld.conf:1)
         port 443 namevhost www.domain.tld (/etc/apache2/sites-enabled/domain.tld.conf:1)
                 alias www.domain.tld
                 alias domain.tld
         port 443 namevhost webmail.domain.tld (/etc/apache2/sites-enabled/webmail.domain.tld.conf:1)
                 alias webmail.domain.tld
*:80                   is a NameVirtualHost
         default server www.domain.tld (/etc/apache2/sites-enabled/domain.tld.conf:48)
         port 80 namevhost www.domain.tld (/etc/apache2/sites-enabled/domain.tld.conf:48)
                 alias www.domain.tld
                 alias domain.tld
         port 80 namevhost webmail.domain.tld (/etc/apache2/sites-enabled/webmail.domain.tld.conf:39)
                 alias webmail.domain.tld

我还将webmail.domain.tld添加到我的hosts-file(127.0.0.1),当我使用telnet 80进行测试时,它也无法正常工作。

我发现很多帖子说我必须添加NamedVirtualHost:80,但这似乎已被弃用,因为我得到一个错误,该命令不再有效。 我还检查了httpd.conf的REWRITES,但找不到。我还试图删除" domain.tld"作为默认站点的别名,但这也没有什么区别。

相关配置(在2.conf文件中):

<VirtualHost *:443>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    ServerName www.domain.tld
    ServerAlias www.domain.tld domain.tld
    ServerAdmin webmaster@domain.tld
    DocumentRoot /var/www/domain.tld/public_html
    # ....
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    ServerName www.domain.tld
    ServerAlias www.domain.tld domain.tld
    ServerAdmin webmaster@domain.tld
    DocumentRoot /var/www/domain.tld/public_html
    # ....
</VirtualHost>

<VirtualHost *:443>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    ServerName webmail.domain.tld
    ServerAlias webmail.domain.tld

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/webmail
    # ....  
</VirtualHost>

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    ServerName webmail.domain.tld
    ServerAlias webmail.domain.tld

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/webmail
    # ....
</VirtualHost>

请说明这一点。

1 个答案:

答案 0 :(得分:0)

最后结果是缓存。 FireFox正在缓存重定向,当我在InPrivate Chrome / Firefox中进行测试时,它按预期工作。