开发者

Custom URL/Domain (CNAME alias?)

开发者 https://www.devze.com 2023-02-10 08:14 出处:网络
I am creating an application in a LAMP stack and I want to provide the user with the ability to use their own domain instead of a subdomain of my site. eg.

I am creating an application in a LAMP stack and I want to provide the user with the ability to use their own domain instead of a subdomain of my site. eg.

Instead of: http://some_user.mysite.com

They will use: http://store.some_user.com/

I know there are a few companies that provide this using CNAME records. (开发者_Go百科http://help.bigcartel.com/articles/14-using-a-custom-domain) however I'm not sure how they achieve this end-to-end.

My questions are:

  1. What is this process called? (So I can research this further if need be)

  2. What do I need to do to provide this? ie. What do I need to do on the DNS, apache and php side to get this working?

Any advice, links or code snippets would be greatly appreciated.

Thanks


UPDATE

So far I have been able to set up the wildcard DNS entry however I'm still having problems with the CNAME record resolving to the other domain. eg.

http://store.weareunified.com/ -> http://weareunified.joshstuart.com.au/

weareunified.com (this is a test user host) DNS

weareunified.com. A 111.67.3.227
store CNAME weareunified.joshstuart.com.au.

joshstuart.com.au (This is the primary application host) DNS

joshstuart.com.au. A 111.67.3.227
* CNAME joshstuart.com.au.


I have this set up using LAMP and it works very well. Here's how I did it:

  1. The target server with my application on it is on a normal A record (sub)domain. So in your case I'm assuming you have the application running on joshstuart.com.au.
  2. The client needs to change their DNS entry for store.weareunified.com to CNAME to joshstuart.com.au.
  3. The Apache server has a virtualhost without a domain specification (in my case), simply a <VirtualHost *:80>

That's it. There are currently 70+ domains that CNAME to the main application domain, and they each serve their individual site as needed (without a redirect, etc).


Actually, you dont need to do anything.

Your users need to get their DNS provider add a CNAME record that basically maps http://app.some_user.com/ to http://some_user.app.com.

Any DNS client that look for http://app.some_user.com/ is told to look for http://some_user.app.com instead, and so this is a DNS/client issue, not a server issue.

Amazon recommend this very technique for users of EC2 servers.

Please note that CNAME records have a limitation, they cannot be assigned to the root of a domain - your users cannot assign http://some_user.com/, only http://app.some_user.com/ as a CNAME.


I have something similar which I did with the cpanel api2.

Basically, the user points his domain to my dns, and I use the api to park his domain on mine.

I store each user's domain in a database.

On a page load, I extract the http_host and compare it to my database to see if the domain exists. I then load the page based on the users settings(I'm serving all pages from the same script) and database entries.

To reduce database load, I save the info in a session identifying the host. I can then check this on each subsequent load instead of checking the database each time.


The other possibility is to actually be the user's DNS host and handle all the records. You can get open source solution for this. (But you might need own two DNS servers on different subnets).


There's a couple of different parts here - getting the DNS entries set up, and then getting Apache to respond to the request.

Do you have the CNAME set up properly for the customer? Note, you can't set up a CNAME on weareunited.com, it has to be on store.weareunited.com, or some other hostname that is not the root domain.

It sounds like you may not understand how CNAME's work. An overly simplified version is, when a user requests store.weareunited.com, their local nameserver (e.g. the nameserver that is in the end user's ISP. For me on Comcast, it's usually a Comcast NS in Beaverton, OR. This is assuming the local nameserver hasn't already resolved the hostname and doesn't have it in cache) will query the root nameservers to determine who is responsible for the domain. The local namserver will then query the domain nameserver to get the record. The record could be an A record, which is an IP address, or a CNAME, which points to another hostname.

When the local namesever gets the CNAME, it will then run through this process again to get the A record. Once it finally has the A record with the IP address, it will hand back the IP address to the end user's browser, and the web browser will make a request to the IP address.

The end result is the web browser gets an IP address, and it then makes a request to this IP address using the original hostname as the host header - store.weareunited.com. So Apache should be set up to receive requests for the hostname store.weareunited.com.

PHP won't care what the hostname is, unless you are checking environment variables like $_SERVER...

You can get your customers to set up a CNAME to joshstuart.com.au. You could certainly create additional hostnames like weareunited.joshstuart.com.au, or do a wildcard, and then have your customers set the CNAME target to that unique hostname, but why bother? I would just have:

store.weareunited.com.  3600 IN CNAME   joshstuart.com.au.

As long as joshstuart.com.au then hands out an IP address to your web server, the CNAME will work. As I mentioned above, Apache will see a request coming in for store.weareunited.com, so you either need to set up a virtual host for that hostname, or create a generic vhost as Berklee mentions (although I'm not sure what apache directives you would use to ensure the request is then mapped to the proper files for the domain...).

0

精彩评论

暂无评论...
验证码 换一张
取 消