Page 1 of 1

Subdomain difficulties with Apache

PostPosted: 20. February 2012 02:57
by tggrng123
Ok so this has been puzzling me for quite some time.
I have set my dns CNAME records for a subdomain and I’ve set up my virtualhost in Apache http-vhosts.conf like so:

Code: Select all
NameVirtualHost *:80

<VirtualHost *:80>
    ServerAdmin admin@example.com
    DocumentRoot /opt/lampp/htdocs
    ServerName www.example.com
    ServerAlias example.com *.example.com
    ErrorLog logs/example.com-error_log
    CustomLog logs/example.com-access_log common
</VirtualHost>

<Virtualhost *:80>
    ServerAdmin admin@example.com
    DocumentRoot /opt/lampp/htdocs/subdomain
    ServerName subdomain.example.com.com
    ErrorLog logs/subdomain.example.com-error_log
    CustomLog logs/subdomain.example.com-access_log common
</Virtualhost>


What ends up happening is that when I go to subdomain.example.com it starts in the htdocs instead of htdocs/subdomain/ directory. I want it to start in /htdocs/subdomain/ and I cannot figure out how.
Please help, I'd really appreciate it.

Re: Subdomain difficulties with Apache

PostPosted: 20. February 2012 14:16
by JonB
The reason is simple - you nested your VirtualHost. (its a bad idea anyway for a variety of security reasons)

Create a new folder inside /opt/lampp/ to hold your new virtual host. Be sure to give it the same ownership and permissions as htdocs. then point your VirtualHosts directives at that folder. (always leave the first Vhost as a proxy for the default installation)

Good Luck
8)

Re: Subdomain difficulties with Apache

PostPosted: 20. February 2012 23:48
by tggrng123
Thank you for your help, however, it didn't fix it. It's doing the same thing. I have a hunch that it's a dns misconfiguration but I don't know, I'm just getting frustrated now.

PS: Apache's documentation vhosts documentation (http://httpd.apache.org/docs/2.2/vhosts/examples.html) is what I based my config on.

Re: Subdomain difficulties with Apache

PostPosted: 21. February 2012 01:58
by Altrea
Hi tggrng123,

use more different servernames.
your first vhost will match some of the requests your second should match.

If you want to have a vhost that matches, if no other one matches either post it as very first vhost with a servername that will never match (the first vhost is always the default vhost if no default vhost is defined), or use the _default_ pattern.

best wishes,
Altrea

Re: Subdomain difficulties with Apache

PostPosted: 21. February 2012 16:34
by JonB
Altrea is on the right track - your default install should never partially match any vhosts. In my case I usually make the default a 'holding domain' I have (a .net TLD just for holding server hosts) I think you could also make the default an IP address, although I have not tested that theory.

Good Luck
8)

Re: Subdomain difficulties with Apache

PostPosted: 22. February 2012 21:38
by tggrng123
I'll edit this post later this evening to tell confirm it. Thanks guys :)