Apache Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsSystem AdministrationApache Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old February 12th, 2001, 03:09 AM
birdsky birdsky is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Location: Hong Kong or Austin, Texas
Posts: 14 birdsky User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy

Does anyone know how to set up DNS to accept wildcard domain name?

That is, anything.mydomainname.com and anyotherthing.mydomainname.com will be
mapped to the same ip (same ip as mydomainname.com)

Also, if the above-metioned DNS is setup, can a webpage with such domain name
be hosted on a Apache virtual host? I mean, how can I define only one
<virtualhost> directive of Apache so that it will process the requests
to any
of these subdomains automatically.

Thanks a lot!

Bird

Reply With Quote
  #2  
Old February 12th, 2001, 08:06 AM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 13
Send a message via AIM to rod k
I can't tell you how to do the wildcard DNS thing, although I know it can be done.

AFA the Apache side, do you want each to point to a different directory? If so you want to use mod_vhost_alias. It allows you to specify the directory to use for a particular domain, based on the domain name. You can use any and all parts of the domain name to have vhost_alias calculate the directories to use. Then, adding a new name is as simple as creating the directory.

Lets say you have two domains (domain1.com and domain2.com) and you want to have a directory structure like:

/htdocs/domain1/whatever -> whatever.domain1.com
/htdocs/domain2/whatever -> whatever.domain2.com

With mod_vhost_alias installed you could give this directive:

UseCanonicalName Off
VirtualDocumentRoot /usr/local/apache/htdocs/%-2/%-3+

The %-2 tells it to use the second to last part of the domain name (in our example domain1 or domain2). The %-3+ tells it to use the third to last part and any preceeding parts of the domain to determine the next part of the path.

So, http://www.domain1.com would map to /usr/local/apache/htdocs/domain1/www

something.else.domain1.com would map to /usr/local/apache/htdocs/domain1/something.else

There are numerous ways to configure the mapping but something to keep in mind is if the requested URL does not contain a piece it needs to complete the path, a underscore (_) will be used in its place such that (in our example) domain1.com would map to /usr/local/apache/htdocs/domain1/_

This could be problematic but all you would need to do is place a symbolic link between /usr/local/apache/htdocs/domain1/_ and /usr/local/apache/htdocs/domain1/www

See the Apache docs for specifics.

Using mod_vhost_alias you can create new subdomains on the fly just be creating the appropriate directory (again, depending on setting the new domain name in DNS or using DNS wildcarding). If a domain name would map to a non-existent directory the user would get a 404.

HTH

rod


[Edited by rod k on 02-12-2001 at 07:09 AM]

Reply With Quote
  #3  
Old February 12th, 2001, 09:18 AM
birdsky birdsky is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Location: Hong Kong or Austin, Texas
Posts: 14 birdsky User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks a lot for your answer.

actually, i want to have all of the subdomains (except a few, like www.domain1.com) mapped to a single directory.
That is,
www.domain1.com -> /htdocs/www/
allothers.domain1.com -> /htdocs/default_dir/
how can i do this?

seems i don't need the mod_vhost_alias, right? or am i wrong?

if i want to do it in the way u mentioned, should i put the codes in between the <Virtualhost></virtualhost> directive?

Thanks again...

PS. still want help for the DNS wildcarding...

Reply With Quote
  #4  
Old February 12th, 2001, 09:56 AM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Start here -> http://forums.devshed.com/showthread.php?threadid=10403 for enabling wildcard in BIND.

Right, you don't need to use mod_vhost_alias, use mod_rewrite instead. Your case already been covered in the link above but with a bit modification.

RewriteEngine on
RewriteMap lc int:tolower
RewriteCond %{SERVER_NAME} !\.domain1\.com$ [NC]
RewriteRule ^(.+) - [L]
RewriteCond %{SERVER_NAME} ^www\.domain1\.com$ [NC]
RewriteRule ^(.+) - [L]
RewriteCond %{SERVER_NAME} ^[^.]+\.domain1\.com$ [NC]
RewriteRule ^/icons/(.+) - [PT,L]
RewriteRule ^(.+) %{SERVER_NAME}=$1 [C]
RewriteRule ^(.*)=(.*) ${lc:$1}$2 [C]
RewriteRule ^([^.]+)\.domain1\.com(.*) /htdocs/default_dir$2

NameVirtualHost 123.45.67.89

<VirtualHost 123.45.67.89>
RewriteEngine on
RewriteOptions inherit
ServerAdmin birdsky@domain1.com
DocumentRoot /htdocs/www
ServerName www.domain1.com
ScriptAlias /cgi-bin/ "/htdocs/cgi-bin/"
Alias /icons/ "/htdocs/icons/"
<Directory "/htdocs/www">
Options All MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

<VirtualHost 123.45.67.89>
ServerAdmin client@domain1.com
DocumentRoot /htdocs/default_dir
Alias /icons/ "/htdocs/icons/"
<Directory "/htdocs/default_dir">
Options All
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

Reply With Quote
  #5  
Old February 12th, 2001, 07:37 PM
birdsky birdsky is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Location: Hong Kong or Austin, Texas
Posts: 14 birdsky User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Talking

Thank you both!

great. i will try that. since we do not host the DNS ourselves, it might be a little troublesome to change DNS's setting...

by the way, is it ok to have the webserver and DNS hosted on the same machine, in terms of security and feasibility? We only have one machine, and we will have many domains to manage. It's great if we can map all these names by ourselves, but we do not have a secondary DNS.

birdsky

Reply With Quote
  #6  
Old February 12th, 2001, 07:56 PM
birdsky birdsky is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Location: Hong Kong or Austin, Texas
Posts: 14 birdsky User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
One more thing.

Since I am not familiar with the RewriteEngine, I have a few more questions...

Will it alter the host name of the request?
For a request to http://anything.domain1.com/
What will $ENV{HTTP_HOST} return in a script?
(What I want it to return is anything.domain1.com)

Also, if I want to map the request to domain1.com to the same directory as www.domain1.com, how can I do that?

Sorry for the silly questions... Thanks a lot!

Reply With Quote
  #7  
Old February 13th, 2001, 12:05 AM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
>> it might be a little troublesome to change DNS's setting

Yes. But if you just want subdomain.domains.com, just enabling wildcard should do just fine, no more, no less. If you want to host for others, you should then run your own nameserver, master at least, and let your ISP do the slave nameserver (many ISPs do this).

>> is it ok to have the webserver and DNS hosted on the same machine, in terms of security and feasibility?

Yes. There are many ways to secure Apache internally and externally which I am not going to discuss here. As for DNS, you can at least chroot it to minimize the damage in event of a break-in.

>> but we do not have a secondary DNS

Can you request more static IPs? My DSL ISP (SpeakEasy.net) offers each additional IP for $2.95/month. I got 3 already but I think I will request more if I need to. You said you only have one machine, but really, you don't need a power box to run a slave nameserver, a P100 should be more than enough.

>>What will $ENV{HTTP_HOST} return in a script?

Same. A request of http://anything.domain1.com would give you anything.domain1.dom in both HTTP_HOST and SERVER_NAME

>> if I want to map the request to domain1.com to the same directory as www.domain1.com

You still need to enable wildcard or an A record of domain1.com or CNAME of it. Then add ServerAlias domain1.com www.domain1.com within <VirtualHost> block.

Reply With Quote
  #8  
Old February 13th, 2001, 03:29 AM
birdsky birdsky is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Location: Hong Kong or Austin, Texas
Posts: 14 birdsky User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Talking

Thanks a lot, freebsd and rod k!

Your answers are great and helpful!

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationApache Development > Apache and DNS help needed...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway