|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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] |
|
#3
|
|||
|
|||
|
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... |
|
#4
|
|||
|
|||
|
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> |
|
#5
|
|||
|
|||
|
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 |
|
#6
|
|||
|
|||
|
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! |
|
#7
|
|||
|
|||
|
>> 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. |
|
#8
|
|||
|
|||
|
Thanks a lot, freebsd and rod k!
Your answers are great and helpful! ![]() |
![]() |
| Viewing: Dev Shed Forums > System Administration > Apache Development > Apache and DNS help needed... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|