Score:0

apache virtualhost not taked into account

im flag

I have multiple domains and i have imagined that one VirtualHost for each would be the way to go. glpi.localnet.lan is never loaded, whereas web.localnet.lan is always display instead, even if i tip "glpi.localnet.lan" in web browser.

glpi.localnet.lan.conf in sites-enabled:

<VirtualHost *:80>

   ServerName  glpi.localnet.lan
    ServerAdmin [email protected]
   ServerAlias glpi

   Alias /glpi/ /var/www/glpi/
   RedirectMatch ^/$ /glpi/
   DocumentRoot /var/www/glpi

   <Directory />
      Options None
      AllowOverride None
   </Directory>

   <Directory /var/www/glpi>
      Options None
      AllowOverride None
   </Directory>

   <Directory /var/www/glpi/files>
      Options None
      AllowOverride None
      Order allow,deny
      deny from all
   </Directory>

   LogLevel  debug
   CustomLog ${APACHE_LOG_DIR}/glpi-access.log combined
   ErrorLog  ${APACHE_LOG_DIR}/glpi-error.log

</VirtualHost>

Here is web.localnet.lan.conf also in sites-enabled:

<VirtualHost *:80>

   ServerAdmin [email protected]
   ServerName  web.localnet.lan
   ServerAlias web

   DocumentRoot /var/www/html

   <Directory />
      Options None
      AllowOverride None
   </Directory>

   <Directory /var/www/html>
      Options None
      AllowOverride None
   </Directory>

   LogLevel  debug
   CustomLog ${APACHE_LOG_DIR}/web-access.log combined
   ErrorLog  ${APACHE_LOG_DIR}/web-error.log

</VirtualHost>

How can i accomplish the following thing:

  • When i enter glpi.localnet.lan, configuration file glpi.localnet.lan.conf is loaded,
  • When i enter web.localnet.lan, configuration file web.localnet.lan.conf is loaded.

Alone, each configuration file works fine. Combining both leads to only one taken into account and requests found in log file of the configuration file taken into account (even if not the expecting one). (seems to depend which one i add first with a2ensite command ?!).

Soooo many thanks for your help, please feel free to ask for more details i may i forgotten to provide.

Score:0
kr flag

I may be wrong, but does it work if you remove the RedirectMatch line in the glpi vhost? That doesn't look right to me.

From the Apache docs:

RedirectMatch:

The considerations related to the difference between Alias and AliasMatch also apply to the difference between Redirect and RedirectMatch.

AliasMatch:

One subtle difference between Alias and AliasMatch is that Alias will automatically copy any additional part of the URI, past the part that matched, onto the end of the file path on the right side, while AliasMatch will not. This means that in almost all cases, you will want the regular expression to match the entire request URI from beginning to end, and to use substitution on the right side.

In other words, just changing Alias to AliasMatch will not have the same effect. At a minimum, you need to add ^ to the beginning of the regular expression and add (.*)$ to the end, and add $1 to the end of the replacement.

It's possible that that line may be redirecting requests in ways you're not expecting.

If Apache can't match a request to a vhost, it uses the first listed. Depending on your Apache version and platform, there may be a default vhost configured that uses /var/www/html as the document root.

Since your web vhost uses that same docroot, that may be what you end up seeing.

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.