Skip to main content
3 of 4
deleted 100 characters in body
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 265

Apache name-based virtual hosts configured, but both hostnames direct to the same site

First, apologies in advanced. I'm a beginner when it comes to networking/web/http so sorry if I've done something obviously wrong.

I have an apache2 webserver running perfectly on my Raspberry Pi (raspbian) and I recently wanted to make another site. To do this, I am trying to make use of name based virtual hosts. I've obtained another dynamic dns host name from https://my.noip.com/#!/dynamic-dns. I believe I have configured my 2 site conf files correctly and the hosts file.

My two websites are called ashwingupta.ddns.net and javacloudcompile.ddns.net (which is the one I had previously). However, if I connect to either one, I now get the site for ashwingupta.ddns.net. The following are the config files:

hosts

127.0.0.1   localhost
::1     localhost ip6-localhost ip6-loopback
ff02::1     ip6-allnodes
ff02::2     ip6-allrouters

127.0.1.1   raspberrypi
127.0.1.1       javacloudcompile.ddns.net
127.0.0.1       ashwingupta.ddns.net

javacloudcompile.ddns.net.conf

NameVirtualHost *:80
<VirtualHost *:8080>
    ServerName javacloudcompile.ddns.net
    ServerAdmin ashiwingupta@localhost
    DocumentRoot /var/www/html/vhosts/javacloudcompile.ddns.net/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

ashwingupta.ddns.net.conf

NameVirtualHost *:8080
<VirtualHost *:8080>
    ServerName ashwingupta.ddns.net
    ServerAdmin ashiwingupta@localhost
    DocumentRoot /var/www/html/vhosts/ashwingupta.ddns.net/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

I've enabled both sites w/ a2ensite and both claim to have been enabaled correctly. I then refreshed apache w/ service apache2 restart.

(Note, everything is intentionally on 8080, my ISP blocks inbound on 80)

edit: Forgot to mention, I do have Listen 8080 in my ports.conf