0

I configured two sites using the "VirtualHost" method in apache2, but if there is an error in the first configuration file when I call my site, it enters the second site. my configuration files are:

1: audio-castle.live:

<VirtualHost *:80>
Protocols h2
Redirect / https://audio-castle.live
</VirtualHost>
<IfModule mod_ssl.c>
    <VirtualHost *:443>
Protocols h2
ServerName audio-castle.live
ServerAlias www.audio-castle.live
        ServerAdmin

        DocumentRoot /var/www/audiocastle/web

        ErrorLog ${APACHE_LOG_DIR}/error.log

        CustomLog ${APACHE_LOG_DIR}/access.log combined

        SSLEngine on

Include /etc/letsencrypt/options-ssl-apache.conf
        SSLCertificateFile /etc/letsencrypt/live/audio-castle.live/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/audio-castle.live/privkey.pem

<Directory /var/www/audiocastle/web>
AllowOverride All
</Directory>
    </VirtualHost>
</IfModule>

the second file is: gtdvm.com:

<VirtualHost *:80>
ServerName gtdvm.com
Redirect / https://gtdvm.com/
</VirtualHost>

<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName gtdvm.com
ServerAlias www.gtdvm.com
    ServerAdmin 

    DocumentRoot /var/www/gtdvm.com

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

SSLEngine on

Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/gtdvm.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/gtdvm.com/privkey.pem

<Directory /var/www/gtdvm.com>
AllowOverride All
</Directory>
</VirtualHost>
</IfModule>

the problem is when an error occurs in one of these two files, when I access for example audio-castle.live, I reach the site gtdvm.com, if the error is in the audio-castle.live file. my question is: how to avoid this redirect from one site to another when one of them encounters errors? . I use Ubuntu 20.04, apache2.4.46.

Brandon Xavier
  • 2,022
  • 13
  • 15
  • The term you are looking for is [default](https://stackoverflow.com/questions/5427379/apache-default-virtualhost). If you want requests not matching any (valid) configuration to end up in a specific configuration block (instead of just the first encountered), you have to explicitly create such block. – anx Apr 18 '21 at 15:31
  • now you mean block, can you explain? – Marcel Roșca Apr 18 '21 at 15:47
  • The first virtual host (audio-castle.live), on port 80, does not specify the `ServerName` and redirects any query to `https://audio-castle.live`. I would try setting the `ServerName` `ServerAlias` in each part (80/443) of each virtual host. – Chris Apr 18 '21 at 18:11
  • You can give a example? – Marcel Roșca Apr 18 '21 at 18:45
  • As far as my understanding, on Ubuntu, you can set up website profiles under the "site-enabled" dir. Probably it will isolate configurations between different sites and prevents redirection cross over. – NeilWang Apr 18 '21 at 22:52

0 Answers0