I'm trying to make a website that allows you to setup a photo gallery with a custom domain name.
Users of the site don't know how to register or configure domain names, so this has to b开发者_如何学编程e done for them.
User enters desired domain name in a box (we check if it's available) and click 'register' button and our website registers the domain name for them and sets up the website automatically (when user goes to that domain name, the photo gallery just works, no technical skills needed).
Enom has an API for resellers which could let you automatically register a domain on behalf of a user. (I have no affiliation with eNom, nor have I used eNom's products).
Implementation of *.weebly.com
Typically this form of dynamic sub-domaining will use a Wildcard DNS record. This type of record maps a wildcard pattern like *.example.com
to one or more servers.
Let's say you have a blogging site and want to let users choose domain names dynamically. You put up a webpage on www.example.com with a form to let user's select names. So a user signs up and chooses bar.example.com
.
Suppose your DNS server has the following mappings:
foo.example.com > 1.2.3.1
*.example.com > 1.2.3.2
Any request for foo.example.com will route to 1.2.3.1, but any other name, such as bar.example.com, will be served by 1.2.3.2. So when the user is redirected to http://bar.example.com
the browser will hit 1.2.3.2. Note that since no DNS changes needed, there is no propagation delay: the redirect will work instantly.
The software running on 1.2.3.2 would then examine the Host
header in the request, parse the fqdn and strip off .example.com
, and resolve bar
against a database. If a record exists, it will serve up the appropriate response for bar
.
You'd also want to keep a list of reserved names or patterns you plan to use in the future, like www\d*, mail\d*, ns\d*
, so that when a user tries to register the site www07
your blacklist will reject it.
Mapping any domain to bar.example.com
Once the bar.example.com
site exists, the user may want to map a custom domain name like www.widgetsimakeinmyhome.com
to their site. The registration and setup for this is mostly manual, and sites like EasyDNS make it pretty simple. Some registrars may have APIs to make part of this easier for you. These should typically be RESTful or at least HTTP-based APIs, so you can choose which client library you like to use (e.g. urllib2
).
To create the mapping, your database would have a table mapping primary sites like bar
to one or more domain aliases. A person would sign-in and map www.widgetsimakeinmyhome.com
to bar
.
Now your software needs to check the Host
header against both the primary site table and the alias table to resolve to the correct site.
There is no general API for this. You have to check back with your own domain registration organization. This is specific to the related domain provider.
I would recommend http://www.zerigo.com/managed-dns ... a managed DNS api solution. I noticed this service existed when a large website provided mentioned something about them. I'm thinking about using them in my next project (similar setup to what you want) and using eNom for domain registration.
Usually you register a domain via a registrar. These companies often provide proprietary APIs which you can use to do this in an automated way. (Some registries also allow registration without using a third-party registrar, for example DENIC)
The registrar then orders the domain at a registry specific to the top level domain. For the communication between registrar and registry the Extensible Provisioning Protocol was created.
Some registrars also implement EPP as an API for their customers so in theory you could use this protocol and switch to another registrar without having to use a new API. I have not done this yet so maybe you have to make adjustments when you actually switch registrars.
精彩评论