logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Virtual Subdomain
Author
nitesh.apte



Joined: 25 Aug 2010
Posts: 21
Location: India

PostPosted: Mon 15 Nov '10 14:06    Post subject: Virtual Subdomain Reply with quote

Hi

I have project folder in /var/www named domain(i.e. /var/www/domain). I have created virtual host www.domain.com pointing to /var/www/domain. Is it possible that www.domain.com and www.subdomain.domain.com should point to /var/www/domain? Because, requirement is like when different user access the portal, they should see their logo and images. So, plan is like we create account and a URL like www.client.domain.com. When client/user will access this link, URL will be parsed and accordingly their logos will be displayed. And in actual, there is no subdomain folder is present.

So, is it possible that www.domain.com and www.subdomain.domain.com should point to /var/www/domain?


Thanks
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Mon 15 Nov '10 18:56    Post subject: Reply with quote

Certainly, and inside the <VirtualHost> container might look something like this

ServerName www.domain.com
ServerAlias www.anotherdomain.com
ServerAlias www.junglegeorge.domain.com www.junglejane.domain.com
ServerAlias www.myname.domain.com www.yourname.domain.com www.hisname.domain.com
DocumentRoot /var/ww/domain


Doing this, using ServerAlias, you will want to make sure UseCanonicalName is Off. This is the default in the Windows config but who knows on all the different Linux distros. So find it and verify it is set to Off.

That way URLs will reference the proper hostname in use and not revert to the one set in ServerName, unless the visitor is actually at www.domain.com.
Back to top
nitesh.apte



Joined: 25 Aug 2010
Posts: 21
Location: India

PostPosted: Tue 16 Nov '10 13:26    Post subject: Reply with quote

I tried as per your description. Nothing happened. Here is the my VirtualHost setting:
<VirtualHost 127.0.1.1>
ServerName www.domain.com
ServerAlias *.domain.com
DocumentRoot /var/www/domain
UseCanonicalName Off
DirectoryIndex index.php
<Directory /var/www/domain>
AllowOverride All
Options All
</Directory>
</VirtualHost>

Entry in /etc/hosts:
127.0.1.1 www.domain.com

Am I doing something wrong?

Thing is like, I don't want manual entries like www.(anything).domain.com inside <VirtualHost>. But, I want that any subdomain (like www.(anything).domain.com) entered in URL should point to /var/www/domain. Is this possible?
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Tue 16 Nov '10 14:36    Post subject: Reply with quote

You also have to add the other test domains into your hosts file

e.g. /etc/hosts
Code:

127.0.0.1 example.com
127.0.0.1 www.example.com
127.0.0.1 www.hisname.example.com
127.0.0.1 sub1.example.com
127.0.0.1 sub2.example.com


Also the IP you entered is wrong.
right 127.0.0.1
wrong 127.0.1.1

Change that in the apache config file and in the hosts file

Your ServerAlias is correct with the wildcard[1]



[1] http://httpd.apache.org/docs/2.2/en/vhosts/name-based.html#using
Back to top
nitesh.apte



Joined: 25 Aug 2010
Posts: 21
Location: India

PostPosted: Tue 16 Nov '10 15:21    Post subject: Reply with quote

That's the thing. I don't want to enter the subdomain URL in /etc/hosts. We are planning like in www.(anything).domain.com - (anything) will be our client name. There are more than 50 client (and will increase in future) and they want to see their company logos when they access a subdomain. From subdomain name we will parse URL and will query our database and will show their logos and images. So making entries /etc/hosts file for so many client is not a good idea. So, is there any way that we can achieve this (without entry in /etc/hosts)?

Or, may be we have to provide a simple login page. So that, after login they can see their logos and images.

Hope, I explained my problem properly. If there is a way to achieve the above said requirement, please help me out.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Tue 16 Nov '10 20:29    Post subject: Reply with quote

If you don't want to put that into your host file (which works only localy) you have to use a DNS server which offers wildcard support.
Back to top
nitesh.apte



Joined: 25 Aug 2010
Posts: 21
Location: India

PostPosted: Wed 17 Nov '10 13:08    Post subject: Reply with quote

Thanks a lot for idea. I made it work. I installed bind9 on my system and did the required configuration. Now, no need to enter anything in /etc/hosts.

There is only one problem, when I restart my system, entries made in /etc/resolv.conf file get deleted. How can I fix this?
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Wed 17 Nov '10 14:30    Post subject: Reply with quote

Which Distro do you use? I guess the resolve.conf is deleted cause you use DHCP and the system generates a new resolv.conf to put in the newest DNS server and stuff.
Back to top
nitesh.apte



Joined: 25 Aug 2010
Posts: 21
Location: India

PostPosted: Sat 20 Nov '10 16:08    Post subject: Reply with quote

I am using Ubuntu 10.04. By the way, I solved the problem. I made an entry in dhcpclient.conf file - prepend domain name as my IP address.

By the way, thanks a lot for you guys' concern.
Back to top


Reply to topic   Topic: Virtual Subdomain View previous topic :: View next topic
Post new topic   Forum Index -> Apache