Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Yet another Virtual Hosting topic

  1. #1

    Default Yet another Virtual Hosting topic

    Ok i have been working all day trying to get virtual hosting all setup. Read threw forum posts and google

    just to explain what i am trying to accomplish with vhosts

    1. xxxxx.com
    2. yyyyy.com


    in listen.conf i uncommented

    Code:
    NameVirtualHost *:80
    in /etc/apache2/vhosts.d i have made 2 conf files

    xxxxx.conf
    Code:
    <VirtualHost *:80>
            ServerAdmin admin@example.com
            DocumentRoot /home/xxxxx/public_html
            ServerName xxxxx.com
            ServerAlias xxxxx.com *.xxxxx.com
    </VirtualHost>
    yyyyy.conf

    Code:
    <VirtualHost *:80>
            ServerAdmin admin@example.com
            DocumentRoot /home/yyyyy/public_html
            ServerName yyyyy.com
            ServerAlias yyyyy.com *.yyyyy.com
    </VirtualHost>
    now if i go to xxxxx.com it displays the correct page
    I am unable to go to yyyyy.com as DNS has not switched yet, but once dns updates i assume it will work

    Problem is before i setup the vhosts i was using the default dir /srv/www/htdocs and if i went to 192.168.x.x with browser it displayed the contents of said directory

    now after vhosts if i go to 192.168.x.x it shows the yyyyy.com page ????

    Any idea how to fix this

  2. #2
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,683
    Blog Entries
    4

    Default Re: Yet another Virtual Hosting topic

    Under virtual hosts, the first vhost becomes the default website. What I normally do is create an aaa_default.conf in vhosts.d that just points to the default site. I normally leave the default website empty so that web vermin can feed all they want on nothing.

  3. #3

    Default Re: Yet another Virtual Hosting topic

    thanks for the info. I created aaa_default.conf in vhosts
    and set to /srv/www/htdocs

    works

    thanks again

  4. #4
    Join Date
    Jun 2008
    Location
    Oklahoma, US
    Posts
    822

    Default Re: Yet another Virtual Hosting topic

    ken yap wrote:

    >
    > Under virtual hosts, the first vhost becomes the default website. What I
    > normally do is create an aaa_default.conf in vhosts.d that just points
    > to the default site. I normally leave the default website empty so that
    > web vermin can feed all they want on nothing.
    >
    >


    As ken stated above, the first 'installed' vhost is considered the default
    host.

    I imagine that xxxx.com and yyyy.com sort alphabetically in
    the /etc/apache2/vhosts.d subdir with yyyy.com first.

    (gotta love abstracted conversations!)

    Again, ken has a good recommendation, naming the hosts to put them in a
    particular order.

    I use:

    00-default.host.com.conf
    10-first.host.com.conf
    20-second.host.com.conf

    Helps me keep track of which file goes for what, and often I end up copying
    (or even linking!) the default.host.conf file (00) to the vhost I want as a
    default. (if any, again, kudos to ken for his 'vermin feeder')

    --
    L R Nix
    lornix@lornix.com

  5. #5

    Default Re: Yet another Virtual Hosting topic

    I have a similar problem trying to use a named virtual host subdomain

    In vhosts.d I have a config file for maindomain.com and one for subdomain.maindomain.com

    <VirtualHost *>
    ServerAdmin admin@maindomain.com
    DocumentRoot /home/maindomain/public_html
    ServerName maindomain.com
    # needed for named virtual hosts
    UseCanonicalName Off
    </VirtualHost>

    <VirtualHost *>
    ServerAdmin admin@subdomain.maindomain.com
    DocumentRoot /home/subdomain/public_html
    ServerName subdomain.maindomain.com
    # needed for named virtual hosts
    UseCanonicalName Off
    </VirtualHost>

    (I have an actual domain name pointing to my external ip which is static, used 'maindomain' and 'subdomain' here just as an example of how I've set things)

    NameVirtualHost * is uncommented in listen.conf

    I've added an A record for subdomain.maindomain.com in the dns server via yast, points to the machine's ip on the lan, didn't wanna fool around giving every subdomain I may add it's own lan ip

    As far as I can tell that's resolving ok, if I do a /dns subdomain.maindomain.com in a mirc running in an xp vm, it resolves to the correct lan ip

    The problem I have is that if I type maindomain.com in a browser it opens the main domain as it should

    But if I type subdomain.maindomain.com it still opens the main domain and not the subdomain

    Yet if I type localhost in a browser it opens the subdomain, and it also opens the subdomain if I type in another address I have that points to my external ip

    Before trying to set up the subdomain, typing the other address I have also opened the maindomain.com

    Not sure why localhost is opening the subdomain unless it's because it's 'above' the main domain in vhosts.d, and I'm at a loss as to what else I can try to make subdomain.maindomain.com work

    Any ideas appreciated

  6. #6
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,683
    Blog Entries
    4

    Default Re: Yet another Virtual Hosting topic

    A few things to check:

    apache needs to be reloaded if any config files have changed.

    The config file needs to end in .conf if it is to be read in (because of the include vhosts.d/*.conf in the master file).

    Check that apache knows about the virtual host with:

    Code:
    /usr/sbin/httpd2 -S

  7. #7

    Default Re: Yet another Virtual Hosting topic

    I've been doing a /etc/init.d/apache2 restart every time I change something and the conf files do all end in .conf

    /usr/sbin/httpd2 -S shows a default server entry as a NameVirtualHost, and it's showing the subdomains directory as it's folder (not sure how that happened)

    Then it shows 2 entries as namevhost, the subdomain and the main domain, the subdomain being listed first, alphabetically speaking it does come first


    The default server was originally the main domain, up until now it's the only domain I've used, but I'm wondering if the default server might not be interfering?

    From what I've read your 'main' domain has to be defined as a virtual host as well for virtual hosting to work, but should a domain be there as the default AND a virtual host?

    I'm not sure how /usr/sbin/httpd2 -S is showing the subdomains folder for the default server in the first place tbh, in default-server.conf it's set as the main domain's folder

  8. #8

    Default Re: Yet another Virtual Hosting topic

    I managed to get the main domain showing as the default-server when running /usr/sbin/httpd2 -S by renaming it's conf file to aa.maindomain.com

    http://localhost still opened the subdomain, so I thought I'd try disabling the subdomain by renaming the conf and restarting apache

    /usr/sbin/httpd2 -S now shows

    VirtualHost configuration:
    wildcard NameVirtualHosts and _default_ servers:
    *:* is a NameVirtualHost
    default server maindomain.com (/etc/apache2/vhosts.d/aa.maindomain.com:1)
    port * namevhost maindomain.com (/etc/apache2/vhosts.d/aa.maindomain.com.conf:1)


    So I'm thinking the only possible folder http://localhost can now open is the maindomain one ... wrong

    It STILL opens the subdomain one, triple-checked that I hadn't inadvertently defined the subdomain's folder for the main domain somewhere and I haven't

    Checked both default-server.conf and aa.maindomain.com.conf for this, as well as yast2_vhosts.conf (I'd previously commented everything in there out anyway)

    I don't even know how it CAN be opening the subdomain for localhost let alone why, especially as using the machine's hostname rather than localhost does open the main domain


    I'm almost beginning to question my own sanity here ...

  9. #9
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,683
    Blog Entries
    4

    Default Re: Yet another Virtual Hosting topic

    Maybe check for syntax errors in your subdomain's conf file. Somehow you have to get apache to parse that file, It's simply not seeing that vhost.

  10. #10

    Default Re: Yet another Virtual Hosting topic

    It was seeing the subdomain until I disabled it

    The reason I disabled it was trying to track down why http://localhost is opening the subdomain instead of the main domain

    Even with it disabled (commented out in all confs etc), localhost still opens the subdomain, even though to all intents and purposes it doesn't exist at the moment

    Whilst it's obvious it shouldn't be doing that, I can't figure out why it is

Page 1 of 2 12 LastLast

Posting Permissions

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