我的服务器上的托管软件允许用户使用 CNAME 将其域指向
我正在创建软件,允许用户拥有自己的自定义子域(例如:theirsubdomain.mydomain.com)或将 CNAME 从他们自己的域指向我的网站地址(例如:theirsubdomain.theirdomain.com)。
我已就此问题联系了我的主机,第一个子域选项很酷。他们将为我设置一个通配符子域脚本...
他们说我无法自动执行 CNAME。我必须手动进入我的帐户并添加域以指向我的网站地址,否则 apache 现在不会在哪里查找文件。
这是常见的做法还是有一种自动化的方法可以解决这个问题?
I am creating software that allows users to either have their own custom subdomain (e.g: theirsubdomain.mydomain.com) or point a CNAME from their own domain to my website address (e.g: theirsubdomain.theirdomain.com).
I've contacted my host about this and the first subdomain option is cool. They will set-up a wilcard subdomain script for me...
The CNAME they said I can't do automatically. I will have to manually go into my account and add the domain to point to my website address otherwise apache wont now where to look for the files.
Is this common practice or is there a way around this that is automated?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题在于 HTTP 标头。当您请求网页时,浏览器会发送一个以以下内容开头的请求:
Host
项允许单个 Web 服务器为多个域提供页面服务。通过查看主机
,服务器知道mypage.html应该来自其为mysite.com存储的文件,而不是来自同一服务器上的myothersite.com的文件。我猜测您的站点位于托管公司的共享 Web 服务器上,并且他们使用此功能来区分对您站点的请求和对位于同一虚拟机上的其他站点的请求。其中一些虚拟主机(例如 HostGator)将允许您指定此
Host
行上应接受的其他域以及返回的文档应来自的位置。这通常是公司提供的更优质的服务。例如,在 HostGator 上,他们说“Baby 和 Business 托管计划允许在一个帐户上托管无限的域名”,但是基本的 Hatchling 计划不允许这样做。如果您有自己租用的机器,并且自己安装了 Apache,则可以自己管理此 HTTP 标头信息的处理。 Apache 支持虚拟主机,请参阅以下文档: http://httpd.apache.org/docs/ 2.2/vhosts/
所以基本上,您必须有某种方式告诉 Apache(或您正在使用的任何服务器)特定
Host
值的文件对应于您的相同文件域,因为单个 Apache 服务器可能提供数百个不同域的文件。如果您不管理自己的 Apache 服务器,则可以按照文档中所示设置虚拟主机,托管服务必须提供某种自定义方式来将此信息传递给 Apache。The issue is the HTTP header. When you request a Web page the browser sends a request that starts out with:
The
Host
item allows a single Web server to serve pages for multiple domains. By looking at theHost
, the server knows that mypage.html should come from its stored files for mysite.com, and not from the files of myothersite.com which is on the same server.I am guessing your site is on a shared Web server at your host company, and they use this functionality to differentiate between requests for your site and requests for other sites that sit on that same virtual box. Some of these virtual hosts, like HostGator, will allow you to specify other domains that should be accepted on this
Host
line and where the returned documents should come from. This often is a more premium service offered by companies. For example on HostGator they say "The Baby and Business hosting plans allow for unlimited domains to be hosted on just one single account", however the basic Hatchling plan does not allow this.If you have your own rented machine, with your own installation of Apache, you can manage the processing of this HTTP header information yourself. Apache supports virtual hosts, see the following documentation: http://httpd.apache.org/docs/2.2/vhosts/
So basically, you have to have some way to tell Apache (or whatever server you are using) that the files for a particular
Host
value corresponds to the same files for your domain, since a single Apache server may be providing files hundreds of different domains. If you are not administering your own Apache server, to where you can set up virtual hosts as shown in the documentation, the hosting service would have to provide some custom way to get this information to Apache.