Apache2 - 始终提供默认的VHOST

时间:2017-05-17 14:06:46

标签: apache apache2 subdomain virtualhost vhosts

我知道有很多问题/答案,但没有一个能解决我的问题。

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

我尝试设置NameVirtualHost *:80,将所有vhost放在一个配置文件而不是单独的配置文件中,在NameVirtualHost *:80内设置ports.conf并指定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}/$1 [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}/$1 [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开放 <body> <div class="container"> <div class="section center"> <h1 class="title"></h1> <section> <div class="purple"></div> <div class="darkgreen"></div> <div class="darkred"></div> </div> </div> </section> </div> </div> <footer class="center"> <p>CREATED BY HARRY BENDIX-LEWIS | 2017</p> </footer> <script src="js/anime.min.js" type="text/javascript"> window.onload = function() { anime({ targets: ['.purple', '.darkgreen', '.darkred'], rotate: 360, borderRadius: '50%', duration: 3000, loop: true }); } </script> </body> 。我做错了什么?

1 个答案:

答案 0 :(得分:1)

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