Virtual Hosts

I am trying to set up a subdomain on my webserver, and from what I can tell, that is called a virtual host on Apache. I tried putting

NameVirtualHost *:80

<VirtualHost *:80>
 DocumentRoot /srv/www/htdocs
 ServerName www.(site).info
 ServerAdmin root@(site).info
 <Directory /srv/www/htdocs>
  AllowOverride None
  Order allow,deny
  Allow from all
 </Directory>
</VirtualHost>

<VirtualHost *:80>
 DocumentRoot /srv/www/mail
 ServerName mail.(site).info
 ServerAdmin root@(site).info
 <Directory /srv/www/mail>
  AllowOverride None
  Order allow,deny
  Allow from all
 </Directory>
</VirtualHost>

and no matter what subdomain i go to, it just takes me to the root domain. I set the hostname settings to redirect mail.(site).info, and www.(site).info to 127.0.0.1, and everything else is set the same as the examples on the Apache2 website. Any idea why it isn’t working?

Use name-based hosts, or for each host create a separate virtual host file?

how would i set up a name based host. According to one of the sites i looked at, that is a name based host. Should I just replace the *:80 with site:80?

You’re right, I overlooked that (the joy of replying too fast while in a hurry)

I do not see much wrong with your config, but you way want to bind them to a specific address and also since these hosts run on one and the same machine, just under different names, you may want (or need) ServerAlias

Docs over here: Name-based Virtual Host Support - Apache HTTP Server

Could it just be as simple as restarting the httpd service after changing the Virtual Hosts? Any changes to the httpd.conf file require restarting the service.

sudo /etc/init.d/httpd restart

Bman22 wrote:

> I am trying to set up a subdomain on my webserver, and from what I can
> tell, that is called a virtual host on Apache. I tried putting

(…)

> and no matter what subdomain i go to, it just takes me to the root
> domain. I set the hostname settings to redirect mail.(site).info, and
> www.(site).info to 127.0.0.1, and everything else is set the same as the
> examples on the Apache2 website. Any idea why it isn’t working?

Maybe this helps :slight_smile:

Apache Web Server & Virtual Host on openSUSE : Part 2
http://vavai.net/2009/03/02/apache-web-server-virtual-host-on-opensuse-part-2/

Greetings,


Camaleón

Ok, that tutorial looks great, I will try it when I get home. I had tried restarting the Apache server, but it seems that I do need the extra stuff in that tutorial. Another question on this topic, is there a way to set the public html directory to be at (username).(site).com instead of (site).com/~(username)?

Yes, but that could be difficult since this is a compile option but I don’t know how SUSE compiles Apache. If they “hardcoded” it to be in ~username, you’ll have to recompile apache again and modify/change that with an option during configure time

from what i can tell, it is just the use of the “public_html” folder that is a compile option, but i think i will just set up virtual hosts for the users i have, unless somebody has a way to do it automatically

I got virtual hosts working, but with one small problem. In order to get the server to go to the main domain name, i have to create another virtual host that loads the main site. Is there anyway to make it so that leaving no subdomain just takes it to the main site without creating a virtual host for it?