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

NameVirtualHost *:80

in /etc/apache2/vhosts.d i have made 2 conf files

xxxxx.conf


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

yyyyy.conf


<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

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.

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

works

thanks again

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

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

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:

/usr/sbin/httpd2 -S

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

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 …

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.

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

Come to the point it’s either give up or redo it all from scratch

So redo the apache and dns from scratch it is then

What fun

I have searched through this thread and don’t think I see my question posted. To make a long story short, I previously has 9.3 and was running Apache with several virtual hosts. I had a flood and lost the linux computer but managed to salvage the hard drive. I wasn’t have to remount the hard drive in the new computer so I got a new one and got 11.0 so I’m back to re-creating the virtual hosting.

I have taken apache pretty much out of the box and added virtual host directives via vhost conf for two different domains ‘www.alpha1imports.com’ and ‘www.jedi-yoda.com’. My problem: regardless of which url entered in the browser, I am going to ‘www.alpha1imports.com’.

I have been working on this problem for the past 20 hours with no results (except for an increase in my blood pressure). Any guidance would be appreciated.

I recall having a similar problem a couple of years ago when I first set the domains/apache server up on the old computer but it was so stable and never a problem that the brain cells and archived answer to a “no access folder”, I guess :slight_smile:

Thanks,

Bob

Forgot NameVirtualHost and binding to name : port properly perhaps?

In the listen.conf NameVirtualHost reads:
NameVirtualHost *:80

Is there somewhere else it needs to be entered at?

Bob

That oughta do it.

How are your <VirtualHost> directives setup?

The Alpha1Imports directives reads as followed:

<VirtualHost *>
DocumentRoot “/home/alpha1/public_html”
ServerName New Page 1
<Directory “/home/alpha1/public_html”>
AllowOverride None
allow from all
Options +Indexes
</Directory>
DirectoryIndex index.htm
</VirtualHost>

and the Jedi-yoda.com directives read as followed:

<VirtualHost *>
DocumentRoot /home/robert/oldlinuxhome/home/rbogge/public_html
ServerName New Page 1
<Directory “/home/robert/oldlinuxhome/home/rbogge/public_html”>
AllowOverride None
allow from all
Options +Indexes
</Directory>
</VirtualHost>

Both are located in the etc/apache2/vhosts.d folder

Bob