apacheubuntu

Any domain from my Apache server gets to the same page


I have the following configuration for Apache on my Ubuntu 24.04 virtual private server:

    <VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName laiguilleconsoude
        ServerAlias laiguilleconsoude
        DocumentRoot /var/www/laiguilleconsoude
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>```

    <VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName lespouletsdefarinet
        ServerAlias lespouletsdefarinet
        DocumentRoot /var/www/lespouletsdefarinet
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>
    VirtualHost configuration:
    *:80                   is a NameVirtualHost
             default server laiguilleconsoude (/etc/apache2/sites-enabled/laiguilleconsoude.conf:1)
             port 80 namevhost laiguilleconsoude (/etc/apache2/sites-enabled/laiguilleconsoude.conf:1)
                     alias www.laiguilleconsoude
             port 80 namevhost lespouletsdefarinet (/etc/apache2/sites-enabled/lespouletsdefarinet.conf:1)
                     alias www.lespouletsdefarinet
    ServerRoot: "/etc/apache2"
    Main DocumentRoot: "/var/www/html"
    Main ErrorLog: "/var/log/apache2/error.log"
    Mutex watchdog-callback: using_defaults
    Mutex default: dir="/var/run/apache2/" mechanism=default
    PidFile: "/var/run/apache2/apache2.pid"
    Define: DUMP_VHOSTS
    Define: DUMP_RUN_CFG
    User: name="www-data" id=33
    Group: name="www-data" id=33

When I get to laiguilleconsoude.fr I get the correct website, but when I go to the lespouletsdefarinet.fr I get the page for the first one, which set to default server by itself.

Can someone please help me with that, I could not find any help, why is my second website redirecting to the first one? And why the first one is set to the default server? I followed a tutorial from this website: https://www.digitalocean.com/community/tutorials/how-to-install-the-apache-web-server-on-ubuntu-20-04


Solution

  • laiguilleconsoude.fr and laiguilleconsoude are two different things. lespouletsdefarinet.fr and lespouletsdefarinet likewise. None of your virtual hosts is used because the requested host name does not match. That means the default virtual host is used for all incoming requests.. Which always is the first defined virtual host according to the documentation. Which explains why all requests are handled the same.

    You need to change your configuration such that ServerName and ServerAlias contain valid host names matching the requests ones:

        ServerName laiguilleconsoude.fr
        ServerAlias www.laiguilleconsoude.fr
    

    Besides ... I hope those "files" in the folder sites-enabled are actually not files, but symbolic links ("symlink") inside the file system pointing to the respective files in the folder ../sites-available. That is the desired setup. And I fail to see a reason why you would want to disable the default configuration at all ...