如何设置像 blogspot 这样的子域

发布于 2024-07-09 04:29:35 字数 69 浏览 4 评论 0原文

当用户注册我的网站时,应该如何为他们设置子域。

需要哪些基础设施? 我正在使用 Linux 服务器。

What should do to setup a sub-domain for the users when they sign-up into my site.

What are the infrastructure required? I am using Linux servers.

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

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

发布评论

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

评论(5

-柠檬树下少年和吉他 2024-07-16 04:29:35

您可以为每个已知子域使用特定的 DNS(CNAMEA/AAAA)条目,也可以使用通配符 DNS 条目ll 接受 *.example.com:

$ORIGIN example.com
foo     IN A 12.34.6.78
bar     IN A 12.34.6.78

$ORIGIN example.com
*       IN A 12.34.6.78

后者的优点是,一旦服务运行,就无需更改 DNS 或 Apache 配置。 缺点是所有此类通配符查找必须(根据定义)最终返回相同的 IP 地址。

Apache 配置将取决于您对最终用户控制和安全性的要求。 请注意,如果用户有权在服务器上运行 CGI 脚本,则需要进行额外的设置以确保安全完成。

根据内容是静态还是动态,这也会影响您的配置:

  1. 使用 mod_vhost_alias 将各个虚拟主机映射到服务器上各自的目录。

  2. 如果您确实想要,请为每个已知站点创建一个单独的 部分,但是每次新用户登录时您都必须重新启动 Apache up

  3. 使用单个 ,然后在脚本中查看所请求 URL 的主机名部分(来自 $SERVER_NAME 环境变量)渲染输出以确定要显示哪个用户的内容。

You can either use a specific DNS (CNAME or A/AAAA) entry for each known subdomain, or a wild-card DNS entry that'll accept *.example.com:

$ORIGIN example.com
foo     IN A 12.34.6.78
bar     IN A 12.34.6.78

or

$ORIGIN example.com
*       IN A 12.34.6.78

The advantage of this latter is that no changes are required to either DNS or Apache configuration once the service is running. The disadvantage is that all such wildcard lookups must (by definition) end up returning the same IP address.

The Apache configuration will depend on your requirements, both for end-user control and security. Note that if the users have permission to run CGI scripts on the server then additional setup will be needed to ensure that that's done securely.

Depending on whether content is static or dynamic this will also affect your configuration:

  1. Use mod_vhost_alias to map individual virtual hosts into their individual directories on the server.

  2. If you really want, create a separate <VirtualHost> section for each known site, but then you'll have to restart Apache each time a new user signs up

  3. Use a single <VirtualHost> and then look at the hostname part of the requested URL (from the $SERVER_NAME environment variable) in the scripts that render the output to figure out which user's content to display.

暖树树初阳… 2024-07-16 04:29:35

您可以在 DNS 设置中为每个子域创建 CNAME 条目/A 记录

CNAME 记录是您的
允许的域管理设置
您可以控制您的子域
域名。

要使其与注册一起自动化,您可以编写一个脚本,在每个用户注册时执行该脚本。

您也可以参考此链接,了解 Apache 的分步过程:

如何在 apache 中设置子域

(既然你提到了 Linux,我认为它一定是 APache。如果是,请说明否则)

替代解决方案

您还可以参考通配符解决方案,由 Alnitak 给出,在同一线程中。 我发现他的方法更简单。 :)

You can make a CNAME entry/ A Record in your DNS settings, for each subdomain

A CNAME record is a record in your
Domain Management Settings that allows
you to control a subdomain of your
domain.

To automate it along with registration, you can write a script which is executed for each user, when s/he registers.

You can refer to this link, as well, for a step-by-step process for Apache:

How to setup subdomains in apache

(since you mentioned Linux, I assume it must be APache. Please mention if it is otherwise)

Alternate Solution

You can also refer to the wildcard solution, given by Alnitak, in the same thread. I find his is an easier way. :)

寂寞陪衬 2024-07-16 04:29:35

基础设施包括访问dns服务器以添加通配符条目,以及在Apache中重写规则。

尝试这些答案:

或此链接:

infrastructure includes access the the dns server to add a wildcard entry, and rewrite rules in Apache.

Try these answers:

or this link:

山人契 2024-07-16 04:29:35

如果您使用 Linux 服务器,我假设您使用 Apache 作为网络服务器。

您必须为子域和虚拟主机设置正确的 DNS 路由。

虚拟主机的设置相当容易,但我不确定以编程方式动态设置它们有多容易。

大多数时候,就像编辑 apache 配置文件并添加以下内容一样简单:

Port 80
ServerName www.mydomain.com

NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /www/user-bob
ServerName bob.mydomain.com
...
</VirtualHost>

<VirtualHost *:80>
DocumentRoot /www/user-sally
ServerName sally.mydomain.com
...
</VirtualHost> 

VirtualHost Documention 可能对您有用。

If your using Linux server's I'm assuming your using Apache as your webserver.

You'll have to setup proper DNS routing for the sub domain as well as a virtual host.

Virtual Hosts are fairly easy to setup but I'm not sure how easy it is to do them on the fly progmatically.

Most of the time it's as easy as editing your apache config file and adding the following:

Port 80
ServerName www.mydomain.com

NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /www/user-bob
ServerName bob.mydomain.com
...
</VirtualHost>

<VirtualHost *:80>
DocumentRoot /www/user-sally
ServerName sally.mydomain.com
...
</VirtualHost> 

The VirtualHost Documention will probably of some use to you.

鲜肉鲜肉永远不皱 2024-07-16 04:29:35

Apache 允许您根据单个服务器上的子域指定任意数量的“站点”。 创建一个新的“站点定义”文件,其中包含适当的子域信息以及适当的 DNS 通配符,即可完成您想要的操作。

换句话说,该过程如下:

  1. 设置通配符,以便 *.mysite.com 定向到正确的服务器。
  2. 当新用户注册时,创建正确的 Apache 站点定义文件 - 您可能会有一个基本模板,您可以将正确的子域信息放入其中并保存。
  3. 让 Apache 重新读取其配置。
  4. 利润。

重要这是基于 Debian 风格的 Apache 配置,其中配置文件包含在一个目录中,主配置读取该目录中的所有配置文件。 这将大大简化事情,因为添加/删除子域将意味着添加/删除文件,而不是编辑单个文件,因此该过程将更容易自动化。

Apache allows you to specify any number of 'sites' based on subdomains on a single server. Creating a new 'site definition' file with the appropriate subdomain information in it, along with proper DNS wildcards, will do what you want.

In other words, the process is like this:

  1. Setup wildcards so that *.mysite.com directs to the proper server.
  2. When a new user signs up, create the proper Apache site definition file - you'll probably have a base template that you put the right subdomain information into and save.
  3. Make Apache re-read its configuration.
  4. Profit.

IMPORTANT This is based on a Debian-style Apache configuration, where the config files are included in a directory, and the main configuration reads all the config files in that directory. This will simplify things a great deal, because adding/removing subdomains will mean adding/removing files, rather than editing a single file, and so the process will be much easier to automate.

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