1

I have a ubuntu server with apache setup, the main domain on the server is a subdomain app.example.com, which is working fine.

Now if I setup john.app.example.com, then that also is displaying the web page of app.example.com, the DocumentRoot for john.app.example.com is different, still it shows the web page of app.example.com. how can I resolve this, so john.app.example.com displays the pages that are there in its DocumentRoot.

Sam Cogan
  • 38,736
  • 6
  • 78
  • 114

1 Answers1

1

1 Check active NameVirtualHost. Open /etc/apache2/ports.conf file:

NameVirtualHost *:80

2 Check DNS

# ping app.local
PING localhost.localdomain (127.0.0.1) 56(84) bytes of data.

# ping john.app.local
PING localhost.localdomain (127.0.0.1) 56(84) bytes of data.

3 Check Apache config(/etc/apache2/sites-enabled/000-default):

<VirtualHost *:80>
        ServerName app.local
        DocumentRoot /var/www
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>
</VirtualHost>

<VirtualHost *:80>
        ServerName john.app.local
        DocumentRoot /var/www/john
</VirtualHost>

$ sudo apache2ctl configtest
Syntax OK

$ sudo  apache2 -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80                   is a NameVirtualHost
         default server app.local (/etc/apache2/sites-enabled/000-default:1)
         port 80 namevhost app.local (/etc/apache2/sites-enabled/000-default:1)
         port 80 namevhost john.app.local (/etc/apache2/sites-enabled/000-default:12)

4 Test Apache:

$ curl http://john.app.local
john
$ curl http://app.local
<html><body><h1>It works!</h1>
<p>This is the default web page for this server.</p>
<p>The web server software is running but no content has been added, yet.</p>
</body></html>
alvosu
  • 8,437
  • 25
  • 22