Score:0

Apache Virtual Hosts - Linking to same website

np flag

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?

in flag
Did you remember to enable the second config file with `a2ensite` then reload Apache?
DeKrypt avatar
np flag
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) `
Score:0
in flag

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.

DeKrypt avatar
np flag
Thank you so much! This helped a lot. Saved so much of my time :)
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.