如何让用户的域名指向他们在我网站中的个人资料

发布于 2024-09-17 22:18:45 字数 243 浏览 7 评论 0原文

我想通过让用户选择将其域名指向他们的个人资料来实现类似 Tumblr 或 Wordpress 的功能。例如,用户转到他们的域名注册商和我的服务器的 IP,那么: www.usersdomain.com 将指向 www.mysite.com/userid 而无需实际转发,以便域名仍将显示在地址栏中。

我希望您能详细描述这样做的步骤。

如果有什么区别的话,我正在使用 Ruby on Rails。我的生产环境有Nginx和Passenger。

I want to implement something like Tumblr or Wordpress by giving user the option to have their domain name point to their profiles. For instances user go to their domain registrar and the IP of my server so then: www.usersdomain.com will point to www.mysite.com/userid without actually forwarding so that domain name will still show in the address bar.

I wish you can describe the details for steps of doing so.

I'm using Ruby on Rails if that's make a difference. My production environment has Nginx and Passenger.

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

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

发布评论

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

评论(1

王权女流氓 2024-09-24 22:18:45

我的观点:

  1. 用户更改其站点的 DNS 记录以指向您服务器的 IP 地址。执行此操作后,对其域的每个 HTTP 请求都将被您的 IP 地址和应用程序“捕获”(但是,您应该重新配置您的 HTTP 服务器)。
  2. 每个 HTTP 请求都包含 Host 标头。该标头允许我们创建虚拟主机之类的东西:许多主机只能指向一个 IP;
  3. 在您的应用程序中,只需从请求中提取 Host 并在数据库中查询具有此类主机的用户。
  4. 刷新他页面的内容就这样了。

例如,您的服务IP是100.100.100.100,我的域名是redsocks.com。我需要更改我的域的 DNS(A 记录)以指向您的 IP。据说,我做到了。

当我将浏览器指向我的域时,浏览器会向您自己的 IP,而不是我的 IP 发出以下请求(或类似请求):

GET / HTTP/1.1
Host: redsocks.com
...

您的应用程序具有处理我的请求的代码(伪代码):

user = User.find_by_domain(REQUEST["Host"])
if user == nil
   render_not_found_page
else
   contents = Content.get_contents_of_user(user)
   render_contents_of_user contents 
end

并且我在我的域上查看您的服务中我自己的页面。

My point of view:

  1. Users change DNS records of their sites to point to the IP address of your server. After that operation, every HTTP request to their domains will be "catched" by your IP address and your application (you should reconfigure your HTTP server, however).
  2. Every HTTP request contains the Host header. That header allows us to make such thing as virtual hosting: many and many hosts can point to only one IP;
  3. In your application just extract Host from the request and query your database for user with such host.
  4. Flush contents of his page and that's all.

For example, IP of your service is 100.100.100.100, my domain is redsocks.com. I need to change DNS (an A record) of my domain to point to your IP. Supposedly, I did.

When I point my browser to my domain, the browser makes the following request (or similar) to your own IP, not mine:

GET / HTTP/1.1
Host: redsocks.com
...

Your application has the code (pseudocode) that deals with my request:

user = User.find_by_domain(REQUEST["Host"])
if user == nil
   render_not_found_page
else
   contents = Content.get_contents_of_user(user)
   render_contents_of_user contents 
end

And I see my very own page within your service on my domain.

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