Apache2 wildcard not showing correct DocumentRoot


Quebec

For some reason my apache2 server was showing me the contents of another virtual host instead of the wildcard virtual host.

When I type hello.purecore.io, the apache2 server will show what is in api.purecore.io and show another folder.

The virtualhost configuration for my wildcard domain is

<VirtualHost *:80>
  DocumentRoot /var/www/wildcard.purecore.io
  ServerName wildcard.purecore.io
  ServerAlias *.purecore.io
</VirtualHost>

and save as "00_wildcard.purecore.io.conf", the virtual host for api.purecore.io is

<VirtualHost api.purecore.io:80>
        DocumentRoot /var/www/api.purecore.io/
        ServerName api.purecore.io
        ServerAdmin [email protected]
</VirtualHost>

and save it as api.purecore.io.conf. so,

  1. When entering any random subdomain other than api.purecore.io, it should load content from /var/www/wildcard.purecore.io,
  2. When accessing api.purecore.io, content should be loaded from /var/www/api.purecore.io/

But for some reason the contents of /var/www/api.purecore.io/ are also displayed when visiting a random domain.

Nick 3500

Apache processes these parts <VirtualHost>sequentially . So be the first to read 00_wildcard.purecore.io.confthe words here api.purecore.io.conf.

But that line ServerAlias *.purecore.ioincludes domain api.purecore.io, so it uses that VirtualHost's configuration.

Solution, rename the files to make sure the order is correct. You want to put the most restrictive VirtualHost first, and the wildcards first.

mv 00_wildcard.purecore.io.conf 01_wildcard.purecore.io.conf
mv api.purecore.io.conf 00_api.purecore.io.conf

and restart (or run normally).

FYI: If Apache cannot find another VirtualHost definition that matches the request, the first VirtualHost is always the default.

FYI 2: No need <VirtualHost api.purecore.io:80>, place <VirtualHost *:80>, order is the solution here.

Related


Apache2 wildcard not showing correct DocumentRoot

Quebec For some reason my apache2 server was showing me the contents of another virtual host instead of the wildcard virtual host. When I type hello.purecore.io, the apache2 server will show what is in api.purecore.io and show another folder. The virtualhost c

Apache2 wildcard not showing correct DocumentRoot

Quebec For some reason my apache2 server was showing me the contents of another virtual host instead of the wildcard virtual host. When I type hello.purecore.io, the apache2 server will show what is in api.purecore.io and show another folder. The virtualhost c

Apache2 wildcard not showing correct DocumentRoot

Quebec For some reason my apache2 server was showing me the contents of another virtual host instead of the wildcard virtual host. When I type hello.purecore.io, the apache2 server will show what is in api.purecore.io and show another folder. The virtualhost c

Apache2 wildcard not showing correct DocumentRoot

Quebec For some reason my apache2 server was showing me the contents of another virtual host instead of the wildcard virtual host. When I type hello.purecore.io, the apache2 server will show what is in api.purecore.io and show another folder. The virtualhost c

Apache2 wildcard not showing correct DocumentRoot

Quebec For some reason my apache2 server was showing me the contents of another virtual host instead of the wildcard virtual host. When I type hello.purecore.io, the apache2 server will show what is in api.purecore.io and show another folder. The virtualhost c

Warning: DocumentRoot x does not exist when starting apache2

Jared Eitnier I cloned a rack server with some extra directories that /var/www/I don't want . I just want to delete unwanted websites on this server. I thought it would be as simple as deleting directories and all files in each directory. So I removed it all v

Warning: DocumentRoot x does not exist when starting apache2

Jared Eitnier I cloned a rack server with some extra directories that /var/www/I don't want . I just want to delete unwanted websites on this server. I thought it would be as simple as deleting directories and all files in each directory. So I removed it all v

Warning: DocumentRoot x does not exist when starting apache2

Jared Eitnier I cloned a rack server with some extra directories that /var/www/I don't want . I just want to delete unwanted websites on this server. I thought it would be as simple as deleting directories and all files in each directory. So I removed it all v

Apache server not showing correct website

hardcoded programmer Hi I'm trying to learn apache2 using a VPS. So far so good, but I can't find the cause of one of the issues I'm facing. I have a website setup /var/www/mydomain.comin my folder . I am in /etc/apache2/sites-available/mydomain.com.conf. Now

Multiple DocumentRoot directives in Apache

Will My question is similar to this with one important difference. I want to be able to serve the file if the lookup in the main DocumentRoot fails, independent of the file's path. On my Apache server, I want to be able to set multiple DocumentRoot directives

Apache, DocumentRoot effect

Sup Found a question about the DocumentRoot directive in Apache's sites-availablefolder file 000-default.confwith: DocumentRoot /var/www/html My /var/wwwfolder layout is: /var/www/owncloud /var/www/html I can't get to the "My Public IP Address" /owncloud

Multiple DocumentRoot directives in Apache

Will My question is similar to this with one important difference. I want to be able to serve the file if the lookup in the main DocumentRoot fails, independent of the file's path. On my Apache server, I want to be able to set multiple DocumentRoot directives

Apache ignores DocumentRoot

Mike Zhukovskiy I am trying to modify the DocumentRoot for a virtual host in Apache. The DocumentRoot setting of the virtual host will be ignored and the entire DocumentRoot will be used instead. In my case, instead of using /Applications/AMPPS/www/public as t

Apache, DocumentRoot effect

Sup Found a question about the DocumentRoot directive in Apache's sites-availablefolder file 000-default.confwith: DocumentRoot /var/www/html My /var/wwwfolder layout is: /var/www/owncloud /var/www/html I can't get to the "My Public IP Address" /owncloud

Apache: 2 SSL certificates, same DocumentRoot

Dusty Grist My website is configured apacheand now I'm trying to setup redirects correctly. My website uses wildcard SSL authentication and my ssl certificate covers *.mydomain.com. My certificate provider only covers one level of subdomains. My website URL is

Apache Main DocumentRoot does not exist

ke4ukz I'm trying to find /var/www/htmlthat there is still a reference to it in my Apache configuration . apache2ctl -SIt shows up when running Main DocumentRoot: "/var/www/html", but neither my virtual host nor my main Apache config file point to that directo

Apache Main DocumentRoot does not exist

ke4ukz I'm trying to find /var/www/htmlthat there is still a reference to it in my Apache configuration . apache2ctl -SIt shows up when running Main DocumentRoot: "/var/www/html", but neither my virtual host nor my main Apache config file point to that directo

Apache Main DocumentRoot does not exist

ke4ukz I'm trying to find /var/www/htmlthat there is still a reference to it in my Apache configuration . apache2ctl -SIt shows up when running Main DocumentRoot: "/var/www/html", but neither my virtual host nor my main Apache config file point to that directo

Ionic 2 loader not showing at correct time

Tashar Walzad I am using a loader in an Ionic 2 app. Initially, I had a menu grid like this - When I click on any menu it navigates to the next page. But since the next page has a lot of data, it takes time to load the next page. So I want to show a loader rig

Ionic 2 loader not showing at correct time

Tashar Walzad I am using a loader in an Ionic 2 app. Initially, I had a menu grid like this - When I click on any menu it navigates to the next page. But since the next page has a lot of data, it takes time to load the next page. So I want to show a loader rig