如何设置像 blogspot 这样的子域
当用户注册我的网站时,应该如何为他们设置子域。
需要哪些基础设施? 我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以为每个已知子域使用特定的 DNS(
CNAME
或A
/AAAA
)条目,也可以使用通配符 DNS 条目ll 接受 *.example.com:或
后者的优点是,一旦服务运行,就无需更改 DNS 或 Apache 配置。 缺点是所有此类通配符查找必须(根据定义)最终返回相同的 IP 地址。
Apache 配置将取决于您对最终用户控制和安全性的要求。 请注意,如果用户有权在服务器上运行 CGI 脚本,则需要进行额外的设置以确保安全完成。
根据内容是静态还是动态,这也会影响您的配置:
使用
mod_vhost_alias
将各个虚拟主机映射到服务器上各自的目录。如果您确实想要,请为每个已知站点创建一个单独的
部分,但是每次新用户登录时您都必须重新启动 Apache up使用单个
,然后在脚本中查看所请求 URL 的主机名部分(来自$SERVER_NAME
环境变量)渲染输出以确定要显示哪个用户的内容。You can either use a specific DNS (
CNAME
orA
/AAAA
) entry for each known subdomain, or a wild-card DNS entry that'll accept *.example.com:or
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:
Use
mod_vhost_alias
to map individual virtual hosts into their individual directories on the server.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 upUse 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.您可以在 DNS 设置中为每个子域创建 CNAME 条目/A 记录
要使其与注册一起自动化,您可以编写一个脚本,在每个用户注册时执行该脚本。
您也可以参考此链接,了解 Apache 的分步过程:
如何在 apache 中设置子域
(既然你提到了 Linux,我认为它一定是 APache。如果是,请说明否则)
替代解决方案
您还可以参考通配符解决方案,由 Alnitak 给出,在同一线程中。 我发现他的方法更简单。 :)
You can make a CNAME entry/ A Record in your DNS settings, for each subdomain
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. :)
基础设施包括访问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:
如果您使用 Linux 服务器,我假设您使用 Apache 作为网络服务器。
您必须为子域和虚拟主机设置正确的 DNS 路由。
虚拟主机的设置相当容易,但我不确定以编程方式动态设置它们有多容易。
大多数时候,就像编辑 apache 配置文件并添加以下内容一样简单:
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:
The VirtualHost Documention will probably of some use to you.
Apache 允许您根据单个服务器上的子域指定任意数量的“站点”。 创建一个新的“站点定义”文件,其中包含适当的子域信息以及适当的 DNS 通配符,即可完成您想要的操作。
换句话说,该过程如下:
重要这是基于 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:
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.