Configuring subdomain using apache virtualhost problem
7,706
Solution 1
In VirtualHost have to use the same signature as in NameVirtualHost:
<VirtualHost *:80>
Solution 2
Here is how I do subdomains on my apache2 server...
NameVirtualHost *:80
# Many other hosts...
<VirtualHost servers.international-anarchy.com>
ServerName servers.international-anarchy.com
DocumentRoot "/http/international-anarchy.com/servers/"
<Directory "/http/international-anarchy.com/servers/">
Options +Indexes FollowSymLinks
AllowOverride None
Allow from all
Order allow,deny
</Directory>
</VirtualHost>
<VirtualHost status.international-anarchy.com>
ServerName status.international-anarchy.com
DocumentRoot "/http/international-anarchy.com/status/"
<Directory "/http/international-anarchy.com/status/">
Options +Indexes FollowSymLinks
AllowOverride All
Allow from all
Order allow,deny
</Directory>
</VirtualHost>
That is how I get apache2 to render the subdomains for each host correctly, and I place all of these settings in a virtual hosts file that is included directly from the main apache config.
Related videos on Youtube
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Author by
Admin
Updated on September 17, 2022Comments
-
Admin almost 2 years
I'm trying to use a virtualhost in my Apache configuration to setup a subdomain. My settings are:
NameVirtualHost *:80 <VirtualHost *> ServerName www.website.com DocumentRoot "/var/www/html" </VirtualHost> <VirtualHost *> ServerName wiki.website.com DocumentRoot "/var/www/dekiwiki" </VirtualHost>
When I restart apache, both www.website.com and wiki.website.com go to the main website in /var/www/html.
Any help appreciated.
-
dunxd over 14 yearsThat looks ok to me. The config file you are using is definitely the one that Apache is using right? You've cleared the cache in your browser? You haven't set ServerName or ServerAlias anywhere else in the config?
-
Admin over 14 yearsYes, because if I alter it to just having the wiki virtualhost, it appears. And if I change the order to having the wiki first, it only shows the wiki. No, the servername/alias are commented out of the main config. I can only get it to show either the wiki or the normal website at the moment.
-
Urda over 14 yearsVirtualMe, did you try setting it up as in my example? Be sure to reboot apache2 of course!
-
-
Urda over 14 yearsI prefer this method, as each virtual host declaration has the hostname built right into it, instead of a dozen <VirtualHost *> lines all over your config files. I also group the V-Hosts by domain name, then subdomain, all in alphabetical order... asite.com wiki.asite.com bsite.com wiki.bsite.com and so on!
-
Mattias over 14 yearsThanks very much! I discovered this a few moments ago through searching a different forum. A relief that it's working now. I realised that the virtualhost wasn't being picked up when running httpd -S