Forum Moderators: phranque

Message Too Old, No Replies

How do I add a VirtualHost automatically?

User-registered domains to point to my server

         

thiessenp

5:54 pm on May 23, 2008 (gmt 0)

10+ Year Member



Hi,

I'm a developer working on a journal management system. One feature I'd like to add for users would be the ability to enter a custom domain for their journal. Traditionally to accomplish this, a Journal Manager would e-mail a domain they registered and I'd add a virtual host in Apache.

For example, suppose a journal had the URL: http://myjournalsite.com/myjournal and the related Journal Manager wanted a custom domain of http://myjournal.com.

Is it possible to add a virtual host to an Apache config through an interface? If so, how would I script this? Do any tools exist to do something like this? Is their a better way than adding a virtual host?

Thank you in advance!
-peter

[edited by: phranque at 2:14 am (utc) on May 24, 2008]
[edit reason] No urls, please. See TOS [webmasterworld.com] [/edit]

jdMorgan

3:00 am on May 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A couple of things come to mind:

First, if you get a dedicated IP address, then anyone can can register a domain and point it to the IP address of your server in their DNS record. All "undefined" Vhosts will resolve to the default virtual server, and you can then use a simple mod_rewrite rule to examine %{HTTP_HOST} and rewrite to a subdirectory space for that domain.

Second, you might consider using subdomains instead of allowing user-registered domains. Aloow users to create subdomains of your domain, and rewrite those to a subdirectory to provide them with storage space.

Both of these sort of tie in together, in that I think you're not going to be happy with the result of what you're asking about implementing if you turn over domain naming to the user. There will be nothing to stop anyone from registering an extremely-offensive domain and pointing it to your server, for example.

I'd go with the subdomain approach personally, and simply refuse to rewrite any subdomain that contains offensive words (fairly easy to do with mod_rewrite). Another upside of this approach is that there is no doubt who owns the domain and who has control of it. And you're not quite so clearly setting yourself up as a hosting service this way...

As far as seeking more automation, look into the RewriteMap function of mod_rewrite, define-able at the server config level. It allows you to activate a script when you get a particular URL request, have that script do something (create a directory, set some variables, return status and/or an associated* file/directory location, etc.), and then return control back to mod_rewrite, which can take action on the results. This allows you great flexibility in automating parts of this project.

(* As in "associative list")

Jim

thiessenp

2:42 pm on May 26, 2008 (gmt 0)

10+ Year Member



lots to think about - thanks!

-peter