Subdomain difficulties with Apache

Problems with the Linux version of XAMPP, questions, comments, and anything related.

Subdomain difficulties with Apache

Postby tggrng123 » 20. February 2012 02:57

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.
tggrng123
 
Posts: 3
Joined: 20. February 2012 02:41
XAMPP Version: 5.6.3
Operating System: Ubuntu 11.10 Oneiric Ocelot

Re: Subdomain difficulties with Apache

Postby JonB » 20. February 2012 14:16

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)
User avatar
JonB
AF Moderator
 
Posts: 3210
Joined: 12. April 2010 16:41
Location: Land of the Blazing Sun
XAMPP Version: 1.8.3-2
Operating System: Windows XP/7 - Fedora 15 1.7.7

Re: Subdomain difficulties with Apache

Postby tggrng123 » 20. February 2012 23:48

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.
tggrng123
 
Posts: 3
Joined: 20. February 2012 02:41
XAMPP Version: 5.6.3
Operating System: Ubuntu 11.10 Oneiric Ocelot

Re: Subdomain difficulties with Apache

Postby Altrea » 21. February 2012 01:58

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
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 6488
Joined: 17. August 2009 13:05
XAMPP Version: 5.5.19
Operating System: W7Ux64

Re: Subdomain difficulties with Apache

Postby JonB » 21. February 2012 16:34

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)
User avatar
JonB
AF Moderator
 
Posts: 3210
Joined: 12. April 2010 16:41
Location: Land of the Blazing Sun
XAMPP Version: 1.8.3-2
Operating System: Windows XP/7 - Fedora 15 1.7.7

Re: Subdomain difficulties with Apache

Postby tggrng123 » 22. February 2012 21:38

I'll edit this post later this evening to tell confirm it. Thanks guys :)
tggrng123
 
Posts: 3
Joined: 20. February 2012 02:41
XAMPP Version: 5.6.3
Operating System: Ubuntu 11.10 Oneiric Ocelot


Return to XAMPP for Linux

Who is online

Users browsing this forum: No registered users and 6 guests