1

I try to host different websites on the same Apache server (Apache 2.4 running on Ubuntu 16.04) by using different virtual hosts. However, when trying to open domain-two.tld the server delivers the webpage of domain-one.tld. Similar behavior is described in this and that question. According to my config files, the answers of those two questions should be implemented already.

The virtual hosts are defined as follows:

<VirtualHost *:80>
    ServerName domain-one.tld
    ServerAlias www.domain-one.tld
    DocumentRoot /var/www/html/domain_one
</VirtualHost>

and

<VirtualHost *:80>
    ServerName domain-two.tld
    ServerAlias www.domain-two.tld
    DocumentRoot /var/www/html/domain_two
</VirtualHost>

Both config files are located in sites-available and are symlinked into sites-enabled by using a2ensite leading to the following directory tree:

sites-enabled/
|-- domain_one.conf -> ../sites-available/domain_one.conf
`-- domain_two.conf -> ../sites-available/domain_two.conf

After the config files have been enabled I restarted apache in order to reload its config files by systemctl restart apache2. In order to test both configuration I added some additional hosts to the /etc/hosts file

127.0.0.1       localhost
127.0.0.1       domain-one.tld
127.0.0.1       www.domain-one.tld
127.0.0.1       domain-two.tld
127.0.0.1       www.domain-two.tld
# some further IPs down here

and accessed both websites locally using curl.

This returns the correct documents as desired. However, accessing both sites via a browser from a remote client Apache delivers domain_one only (could not test for domain-two.tld due to technical reasons, cache is deactivated in browser).

Where does this strange behavior come from? How could I narrow this down?


Update due to @kubanczyk's comment:

  • Question: What is returned to remote curl requests instead of local curl request against localhost?
  • Answer: Correct page contents.

For pvz-sphere.de which is domain_one:

$ curl -v http://www.pvz-sphere.de      # which is domain_one
* Rebuilt URL to: http://www.pvz-sphere.de/
*   Trying 217.160.122.225...
* TCP_NODELAY set
* Connected to www.pvz-sphere.de (217.160.122.225) port 80 (#0)
> GET / HTTP/1.1
> Host: www.pvz-sphere.de
> User-Agent: curl/7.60.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Content-Type: text/html
< Content-Length: 905
< Connection: keep-alive
< Keep-Alive: timeout=15
< Date: Wed, 06 Jun 2018 15:45:32 GMT
< Server: Apache
< 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">

<html>
<head>
<title>SPhERe - Symposium on Pharmaceutical Engineering Research</title>
<meta name="keywords" content="SPhERe, ICTV, TU Braunschweig, PVZ, Zentrum für Pharmaverfahrenstechnik, Institut für Chemische und Thermische Verfahrenstechnik" />
<meta name="description" content="Symposium on Pharmaceutical Engineering Research" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
</head>
<frameset rows="100%">
<frame src="http://ictv.rz.tu-bs.de/SPhERe/" title="SPhERe - Symposium on Pharmaceutical Engineering Research" frameborder="0" noresize="noresize"/>
<noframes>
<body>
<h1>SPhERe - Symposium on Pharmaceutical Engineering Research</h1>
<p><a href="http://ictv.rz.tu-bs.de/SPhERe/">http://pvz-sphere.de/</a></p>
</body>
</noframes>
</frameset>
</html>
* Connection #0 to host www.pvz-sphere.de left intact

For teresa-projekt.de which is domain_two:

$ curl -v http://www.teresa-projekt.de    # which is domain_two
* Rebuilt URL to: http://www.teresa-projekt.de/
*   Trying 217.160.233.207...
* TCP_NODELAY set
* Connected to www.teresa-projekt.de (217.160.233.207) port 80 (#0)
> GET / HTTP/1.1
> Host: www.teresa-projekt.de
> User-Agent: curl/7.60.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Content-Type: text/html
< Transfer-Encoding: chunked
< Connection: keep-alive
< Keep-Alive: timeout=15
< Date: Wed, 06 Jun 2018 15:38:17 GMT
< Server: Apache
< 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">

<html>
<head>
<title>Teresa-Projekt</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
</head>
<frameset rows="100%">
<frame src="http://ictv.rz.tu-bs.de" title="Teresa-Projekt" frameborder="0" noresize="noresize"/>
<noframes>
<body>
<h1>Teresa-Projekt</h1>
<p><a href="http://ictv.rz.tu-bs.de">http://teresa-projekt.de/</a></p>
</body>
</noframes>
</frameset>
</html>
* Connection #0 to host www.teresa-projekt.de left intact
  • I understand how curl accesses 127.0.0.1 but no idea how a remote browser does that. Please edit into the question the output of a remote curl -v http://x – kubanczyk Jun 6 '18 at 15:34
  • @kubanczyk: Please see added output snippets. Using curl from remote works as desired. Using browser with disabled cache or from different machine does not :-/ – albert Jun 6 '18 at 15:52
  • Nah, my browser displays two different pages. – kubanczyk Jun 6 '18 at 19:31
0

After I had a look into the request and response headers as well as to the different log files (after enabling forensic logging), I found out that both the domain redirect (was of type iframe redirection instead of HTTP redirect) and the DNS entries were faulty. Those faulty DNS entries and the redirect made Apache delivering the default VirtualHost since none of the given ServerNamesor ServerAlias matched the requested domains.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.