0

I set up two Apache Virtual Hosts for my two forums. When visiting one of them, it links to the root domain page.

Here is my first virtual host

<VirtualHost *:80>
    ServerName krypt.fun
    DocumentRoot /var/www/flarum/public

    <Directory /var/www/flarum/public>
        Options -Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Require all granted
    </Directory>
    
    ErrorLog /var/log/apache2/flarum_error.log
    CustomLog /var/log/apache2/flarum_access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =krypt.fun
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

And my second,

<VirtualHost *:80>
    ServerName scambaiting.krypt.fun
    DocumentRoot /var/www/scambaiting/public

    <Directory /var/www/scambaiting/public>
        Options -Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog /var/log/apache2/flarum_error.log
    CustomLog /var/log/apache2/flarum_access.log combined
</VirtualHost>

However, scambaiting.krypt.fun simply leads to krypt.fun Any ideas?

2
  • Did you remember to enable the second config file with a2ensite then reload Apache? 🤔
    – matigo
    Nov 13, 2022 at 12:20
  • Yes, I have. My virtual host config looks like this: *:443 krypt.fun (/etc/apache2/sites-enabled/flarum-le-ssl.conf:2) *:80 scambaiting.krypt.fun (/etc/apache2/sites-enabled/scambaiting.conf:1)
    – DeKrypt
    Nov 13, 2022 at 12:26

1 Answer 1

0

The issue is being caused by the names of the configuration files. Using a naming structure that will ensure the "default" site (flarum) is always last in the directory will resolve the issue.

For example, you could do this:

  1. Change to the sites-available directory:
    cd /etc/apache2/sites-available 
    
  2. Disable the sites that are currently enabled:
    sudo a2dissite flarum-le-ssl.conf
    sudo a2dissite scambaiting.conf
    
  3. Rename the configuration files to use a numerical prefix:
    sudo mv scambaiting.conf 100-scambaiting.conf
    sudo mv flarum-le-ssl.conf 999-flarum-le-ssl.conf
    
  4. Re-enable the sites:
    sudo a2ensite flarum-le-ssl.conf
    sudo a2ensite scambaiting.conf
    
  5. Reload Apache:
    sudo service apache2 reload 
    
    Note: Alternatively, you could issue a restart.

Now when traffic to the web server is received it will be first compared against the 100 file, then the 999 file. As you add more sites to your server, you can add (and even re-use) these numbers to ensure sites are compared against the Apache enabled sites in a specific order.

You do not need to use numeric prefixes, of course, but the name for the catch-all configuration file should always be last to appear in an alphabetical directory listing.

1
  • Thank you so much! This helped a lot. Saved so much of my time :)
    – DeKrypt
    Nov 14, 2022 at 11:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .