Results 1 to 10 of 10

Thread: Virtual Hosts

  1. #1

    Default 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
    Code:
    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?

  2. #2
    Join Date
    Jun 2008
    Location
    /dev/belgium
    Posts
    1,946

    Default Re: Virtual Hosts

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

  3. #3

    Default Re: Virtual Hosts

    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?

  4. #4
    Join Date
    Jun 2008
    Location
    /dev/belgium
    Posts
    1,946

    Default Re: Virtual Hosts

    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

  5. #5
    Join Date
    Jun 2008
    Location
    Oregon, US
    Posts
    109

    Default Re: Virtual Hosts

    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.

    Code:
    sudo /etc/init.d/httpd restart

  6. #6
    Camalen NNTP User

    Default Re: Virtual Hosts

    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 :-)

    Apache Web Server & Virtual Host on openSUSE : Part 2
    http://vavai.net/2009/03/02/apache-w...ensuse-part-2/

    Greetings,

    --
    Camalen

  7. #7

    Default Re: Virtual Hosts

    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)?

  8. #8
    Join Date
    Jun 2008
    Location
    /dev/belgium
    Posts
    1,946

    Default Re: Virtual Hosts

    Quote Originally Posted by Bman22 View Post
    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

  9. #9

    Default Re: Virtual Hosts

    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

  10. #10

    Default Re: Virtual Hosts

    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •