0

So I had a free .gq domain which will expire in a few days, so I bought an .xyz domain. What are the things I need to change in Apache (Debian) so that everything will work the way it always did?

I already changed the virtual host config files in /etc/apache/sites-available, ran the command a2dissite NAME-OF-SUBDOMAIN.domain.gq and a2ensite NAME-OF-SUBDOMAIN.domain.xyz. The subdomains still doesn't work. Whenever I try to reach mail.domain.xyz I end up on the www.domain.xyz site.


Summary:

  • Configured Apache2 with domain.gq
  • I now use domain.xyz
  • How do I tell Apache that I don't use old domain anymore but the new one?
  • How do I get my subdomains (vitual host) to work again?

Example of one virtual host file (all other vh files have the same scheme):

<VirtualHost *:80>
        ServerName pic.domain.xyz
        DocumentRoot /var/www/pic/
</VirtualHost>

It works now. I don't exactly know why. The only thing I did was apt update && apt upgrade -y. I don't know if the upgrade was responsible for it, I did only check a 2 hours after I updated.

  • 1
    Please add example of at least one `VirtualHost` configuration file that isn't working. And have you `sudo service apache2 reload` after modifying the configuration? – Esa Jokinen Mar 24 '17 at 09:30
  • The only way that `apt-get upgrade` could have helped is if the configuration was correct but you hadn't restarted the service and the upgrade caused it to restart. The commands didn't touch your configuration. – Esa Jokinen Mar 25 '17 at 16:54

2 Answers2

1

You can list all configured and active VirtualHost's with apache2ctl -S. The listing is supposedly like this:

*:80                   is a NameVirtualHost
         default server www.example.com (/etc/apache2/sites-enabled/000-default:1)
         port 80 namevhost www.example.com (/etc/apache2/sites-enabled/000-default:1)
         port 80 namevhost sub1.example.com (/etc/apache2/sites-enabled/sub1.example.com:1)
         port 80 namevhost sub2.example.com (/etc/apache2/sites-enabled/sub2.example.com:1)

These hostnames are in the same order as filenames in /etc/apache2/sites-enabled/ as actually they are originally Included in /etc/apache2/apache2.conf with Include sites-enabled/.

Now, when the browser send its HTTP request beginning with

GET / HTTP/1.1
Host: sub2.example.com

Apache goes trough the configured ServerName and ServerAlias directives and stops on the first match. If it doesn't find any matches it falls back to the first virtual host (for which the default hosts filename begins with 000- to make it the first file processed).

In order to use the DocumentRootand another directives configured in file sub2.example.com your configuration has to meet these conditions:

  1. /etc/apache2/sites-enabled/sub2.example.comMUST have ServerName sub2.example.com
  2. Any of the former configuration files i.e. 000-default and sub1.example.com MUST NOT have sub2.example.com or *.example.com in ServerName or ServerAlias.

Most likely you have already declared ServerAlias *.example.com in the configuration file where the www.example.com is configured.

Esa Jokinen
  • 46,944
  • 3
  • 83
  • 129
0

When an incoming requests arrives to the Apache server it checks the requested "Host" header in it and it looks for matches in the "ServerName" directive of the virtualhosts it has, if non matches the first defined virtualhost will answer.

In short: Modify the ServerName directive in each virtualhost to make sure the requests get correctly delivered to the virtualhost they must go.

Daniel Ferradal
  • 2,415
  • 1
  • 8
  • 13