在 Rails/Apache 中自动托管用户域
我目前正在开发一个面向用户的 Web 应用程序,该应用程序为每个新用户在网站上提供了自己的子域,这很好(使用 subdomain_fu),但是有没有办法让用户将自己的域映射到该子域?
我知道如何通过 SSH 连接到服务器并手动编辑 Apache Vhosts 文件来手动执行此操作,但是有没有办法自动执行此操作,以便用户只需将其域输入到网站上的一个框中(显然他们' d 必须在其他地方更改自己的 DNS)?
我在 Apache 之上使用 Ruby 1.8 和 Rails 2.3.3。
本质上是出租;
http://user.application.com/article-1
可从以下位置访问
http://userdomain.com/article-1
感谢您的帮助!
I'm currently developing a user facing web application that gives each new user their own subdomain on the site, which is fine (using subdomain_fu), but is there a way to let a user map their own domain to this subdomain?
I know how to do this manually through SSH-ing into the server and editing the Apache Vhosts file by hand, but is there a way to do this automatically so that a user simply enters their domain into a box on the site (obviously they'd have to change their own DNS elsewhere)?
I'm using Ruby 1.8 and Rails 2.3.3 on top of Apache.
Essentially letting;
http://user.application.com/article-1
be accessed from
http://userdomain.com/article-1
Thanks for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这只是您希望用户将不同域名映射到的一个应用程序,对吧?您根本不需要使用虚拟主机,因为无论域名如何,所有请求都将发送到同一个 Rails 应用程序。如果您使用虚拟主机,则默认虚拟主机(处理 http://1.2.3.4 如果用户.application.com 解析为 1.2.3.4) 需要是您的 Rails 应用程序。
I assume this is just one application that you want users to map different domain names to, right? You shouldn't need to use virtual hosting at all, since all requests will go to the same Rails app, regardless of domain name. If you are using virtual hosting, then the default virtual host (the one that handles http://1.2.3.4 if user.application.com resolved to 1.2.3.4) needs to be your Rails app.
例如,您的用户应该能够为他们的域设置指向您的域的 CNAME 记录,然后
让您的应用知道他们想要使用
userdomain.com
作为主机名。我认为您不必更改虚拟主机设置,因为您的服务器将看到对user.application.com
的请求,但请通过设置您自己的 CNAME 来测试这一点以确保确定。然后,在您的应用程序中,您需要查看主机名,如果它包含
application.com
,您就按照现在的方式执行操作,但如果不包含,则检查是否有用户已设置该域名是他们的。Your users should be able to set up a CNAME record for their domain pointing to your domain, e.g.
and then let your app know that they want to use
userdomain.com
as their hostname. I don't think you will have to change your vhost settings because your server will see the request foruser.application.com
, but test this by setting up a CNAME of your own to be sure.In your app you will then need to look at the hostname and if it contains
application.com
you do as you do now, but if it doesn't you check to see if there's a user who has set that domain as theirs.