Apache2 - 始终提供默认 VHOST

Apache2 - always serves default VHOST

我知道有很多问题/答案,但是none确实解决了我的问题。

我的设置: - 我有 2 个子域(sub1.test.de 和 sub2.test.de),它们被配置为执行代理重定向到相同的 IP(我的虚拟机的 IP,在其他地方) - 我的虚拟主机有两个配置文件 - 虚拟机是 运行 Ubuntu 14.04

我尝试设置 NameVirtualHost *:80,将所有虚拟主机放在一个配置文件中而不是单独的配置文件中,在 ports.conf 中设置 NameVirtualHost *:80 并指定 IP 而不是通配符,但没有运气。打开 sub2.test.de 仍然会将我重定向到 sub1.test.de

这是我的sub1.test.de.conf:

<VirtualHost *:80>
    ServerName sub1.test.de

    ServerAdmin webmaster@test.de
    DocumentRoot /var/www/sub1.test.de/html

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    LogLevel info

    ErrorLog /var/www/sub1.test.de/log/error.log
    CustomLog /var/www/sub1.test.de/log/access.log combined

    # Wildfly api Prox Bypass
    ProxyPass /api http://someip:8080/api
    ProxyPassReverse /api http://someip:8080/api

    # Websocket Proxy Bypass
    RewriteEngine on
    RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
    RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC]
    RewriteRule .* ws://sub1.test.de:9000%{REQUEST_URI} [P]

    ProxyPass /socket http://someip:9000/socket
    ProxyPassReverse /socket http://someip:9000/socket

    <Directory /var/www/sub1.test.de/html>

        # Enable rewriting
        RewriteEngine On

        # If its not HTTPS
        # RewriteCond %{HTTPS} off

        # Comment out the RewriteCond above, and uncomment the RewriteCond below if you're using a load balancer (e.g. CloudFlare) for SSL
        # RewriteCond %{HTTP:X-Forwarded-Proto} !https

        # Redirect to the same URL with https://, ignoring all further rules if this one is in effect
        #RewriteRule ^(.*) https://%{HTTP_HOST}/ [R,L]

        # If we get to here, it means we are on https://

        # If the file with the specified name in the browser doesn't exist
        RewriteCond %{REQUEST_FILENAME} !-f

        # and the directory with the specified name in the browser doesn't exist
        RewriteCond %{REQUEST_FILENAME} !-d

        # and we are not opening the root already (otherwise we get a redirect loop)
        RewriteCond %{REQUEST_FILENAME} !\/$

        # Rewrite all requests to the root
        RewriteRule ^(.*) /

    </Directory>

这是我的 sub1.test.de.conf:

<VirtualHost *:80>
    ServerName sub2.test.de

    ServerAdmin webmaster@test.de
    DocumentRoot /var/www/sub2.test.de/html


    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    LogLevel info

    ErrorLog /var/www/sub2.test.de/log/error.log
    CustomLog /var/www/sub2.test.de/log/access.log combined

    # Wildfly api Prox Bypass
    ProxyPass /api http://someip:8080/api
    ProxyPassReverse /api http://someip:8080/api

    <Directory /var/www/sub2.test.de/html>

        # Enable rewriting
        RewriteEngine On

        # If its not HTTPS
        # RewriteCond %{HTTPS} off

        # Comment out the RewriteCond above, and uncomment the RewriteCond below if you're using a load balancer (e.g. CloudFlare) for SSL
        # RewriteCond %{HTTP:X-Forwarded-Proto} !https

        # Redirect to the same URL with https://, ignoring all further rules if this one is in effect
        #RewriteRule ^(.*) https://%{HTTP_HOST}/ [R,L]

        # If we get to here, it means we are on https://

        # If the file with the specified name in the browser doesn't exist
        RewriteCond %{REQUEST_FILENAME} !-f

        # and the directory with the specified name in the browser doesn't exist
        RewriteCond %{REQUEST_FILENAME} !-d

        # and we are not opening the root already (otherwise we get a redirect loop)
        RewriteCond %{REQUEST_FILENAME} !\/$

        # Rewrite all requests to the root
        RewriteRule ^(.*) /

    </Directory>

apachectl -t -D DUMP_VHOSTS 给我以下输出:

    AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 2a01:4f8:c0c:365::2. Set the 'ServerName' directive globally to suppress this message

VirtualHost configuration:

*:80                   is a NameVirtualHost
         default server sub1.test.de (/etc/apache2/sites-enabled/sub1.test.conf:3)
         port 80 namevhost sub1.test.de (/etc/apache2/sites-enabled/sub1.test.de.conf:3)
         port 80 namevhost sub2.test.de (/etc/apache2/sites-enabled/sub2.test.de.conf:1)

仍然,打开 sub2.test.de 总是给我 sub1.test.de。我做错了什么?

我解决了。问题是,我从列出我的域的地方有一个常规的重定向条目,而不是一个 A-NAME 记录。在我将重定向更改为 A-NAME 记录并等待几个小时进行 DNS 刷新后,一切正常。