wordpress.com 和其他类似服务如何立即创建立即可用的子域?

发布于 2024-07-27 15:00:55 字数 454 浏览 4 评论 0原文

我几乎了解有关子域和 DNS 记录的一切。 我听说过它们,并且只了解基础知识。

实际上,在我的服务器上,我确实在 plesk 下创建了子域,然后联系我的主机来创建正确的 dns。 1-2天内,子域名可以从任何地方访问(我知道,plesk可以自动管理dns,但因为我不知道dns到底是如何工作的,我更喜欢让我的托管服务商处理它们)

但是..当你注册时wordpress.com、posterous.com 等,他们创建一个子域,例如 http://yourname.service_name.com几秒钟后就准备好了..怎么样?

我知道这可能是一个很难回答的问题,因为我的无知我不知道如何更好地表达这个问题 -.-

哦,如果它可以帮助的话,我的环境必须是linux(实际上是debian)

i know almost anything about sub-domains and dns records. i have heard about them and i know just the basics.

Actually, on my server, i do create the subdomain under plesk and then contact my hosting to create the right dns. and in 1-2 days the subdomain is reachable from everywhere (plesk can manage dns automatically, i know, but becose i dont know how does dns exactly works, i prefer to let my hoster handle them)

But.. when you do register on wordpress.com, posterous.com, etc, they create a subdomain like http://yourname.service_name.com that is ready in few seconds.. how?

I know this could be an question hardly to response because my ignorance i dont know how to formulate the question better -.-

Oh, if it can help, my environment must be linux (debian actually)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

甜尕妞 2024-08-03 15:00:55

大多数人通过使用通配符 DNS 记录来实现此目的,这给人一种立即创建子域的感觉。


一旦你有了这样的通配符 DNS 设置:

 *.example.com          A     77.75.105.197

你需要告诉 Apache 你希望所有子域都被虚拟主机捕获,你可以使用 ServerAlias

ServerAlias *.example.com

在 PHP 中,您可以查看 $_SERVER["SERVER_NAME"] 来找出哪个子域已用于访问虚拟主机,然后您可以拥有子域特定的代码/内容。

Most people achieve this by using a Wildcard DNS Record, this gives the appearence of creating subdomains instantly.


Once you've got a wildcard DNS setup like this:

 *.example.com          A     77.75.105.197

You need to tell Apache you want all sub domains to be caught by a virtual host, you can do this with ServerAlias:

ServerAlias *.example.com

In PHP you can then look at $_SERVER["SERVER_NAME"] to figure out what subdomain has been used to access the virtual host, you can then have subdomain specific code/content.

猫九 2024-08-03 15:00:55

astebin.com 的做法如下:

  • 通配符 DNS 记录指向网络服务器 IP 上的所有子域,
  • apache 会将所有对“未知”域的请求发送到第一个虚拟主机 - 您使该主机上的代码能够对该域执行一些有趣的操作名称(在 PHP 中,显示为 $_SERVER['HTTP_HOST']

这样,不需要重新配置 DNS 或 Apache。

Here's the way pastebin.com does this:

  • wildcard DNS record points all subdomains at the webserver IP
  • apache will send all requests for "unknown" domains to the first virtual host - you make the code on that host capable of doing something interesting with the domain name (in PHP, this is presented as $_SERVER['HTTP_HOST']

That way, no DNS or Apache re-configuration is required.

人生百味 2024-08-03 15:00:55

Wordpress 不会创建子域,甚至无法创建子域,因为这是 apache 虚拟主机配置文件的一部分。

创建子域名的唯一方法是创建另一个虚拟主机记录,将其添加到 DNS 记录中,但这需要 24 小时刷新 DNS 服务器。 Plesk 和其他控制面板可以管理它,但 Wordpress 不能,因为它只是 PHP 脚本,可能甚至没有执行此类操作的权限。 此外,您没有指定配置文件的位置,因此 Wordpress 无法知道虚拟主机在哪里:)

请告诉我们更多有关 Wordpress 子域的信息,您在哪里创建它们等。

Wordpress doesn't create subdomain, it even can't create it since this is a part of apaches virtual host configuration files.

The only way to make subdomain is to create another virtual host record, add it to the DNS record, but that takes 24 hours to refresh DNS servers. Plesk and other control panels can manage that, but Wordpress can't since it's only PHP script which probably doesn't even have permissions to do that kind of stuff. Besides, you don't specify where you configuration file is, so Wordpress can't know where virtual host are :)

Please tell us more about that Wordpress subdomains, where you create them etc.

z祗昰~ 2024-08-03 15:00:55

另请注意,您可以通过。 因此它在传入主机名上使用正则表达式,并通过此设置的文档根将其设置为:

/var/www/topleveldomain.com/subdomain/wwwroot

Apache 对其进行了设置, 只需在正确的位置创建一个文件夹即可成为一个新的子域。

另请注意,这与 DNS 记录中的星号别名相关。

然而,我怀疑这就是 WordPress 的做法,而 Paul Dixon 提到的方式可能更有可能。

Also please note that you can via. Apache set it up so it uses a regular expression on the incomming hostname and through this set document root to be something like:

/var/www/topleveldomain.com/subdomain/wwwroot

This can give the illusion that there's been change in config files and all that black magic to allow mysubdomain.topleveldomain.com to become a new subdomain just by creating a folder in the right place.

Also note, this goes with the star aliasing in the DNS record.

However, I doubt that's how wordpress does it and the way Paul Dixon mentions is probably more likely.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文