如何使用同一域为来自不同服务器的两个应用程序提供服务
我有一个在 Heroku 上托管的 Rails 应用程序,该应用程序的服务器生成用于营销/搜索引擎优化目的的页面。我在另一台服务器上还有其他内容页面,它们是静态页面。我想将它们保留在同一个域中,以便在该域上建立 seo 优势。
例如:
domain.com/blah-blah-blah-something
应该真正从 heroku-server-name/blah-blah-blah-something 加载页面,但它看起来像是来自domain.com。
可能的?
I have a Rails app hosted on Heroku which servers generated pages for marketing/seo purposes. I have other content pages on another server, which are static pages. I want to keep them both on the same domain, to build seo goodness on that domain.
example:
domain.com/blah-blah-blah-something
should really load a page from heroku-server-name/blah-blah-blah-something but it LOOKS like it's from domain.com.
Possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在站点前面使用 HAProxy 并将其配置为内容交换。为此,您需要让前端侦听映射到您的外部 IP 的某个内部 IP 地址。后端是您的服务器。您可以设置访问控制列表来确定发送到哪个后端。例如,这可以通过某些路径名或文件扩展名实现(例如 .html 转到服务器 A,.aspx 转到另一个服务器)。最终,用户不知道他们位于两台独立的服务器上,因为他们只看到在一个域名上提供服务的网站。
注:
1)您将无法共享会话(我相信您已经知道这一点)。
2) HAProxy 不处理 https,所以如果你需要 https,那么你必须有一些东西来处理 https 终止,例如 nginx 或 haproxy 或 stunnel。
希望这适用,因为我不熟悉heroku。
You can front the site with HAProxy and configure it for content switching. To do this you have the frontend listen on some internal IP address that's mapped to your external IP. The backends are your servers. You setup access control lists to determine which backend to send to. For example, this could be via some path name or file extension (such as .html goes to server A and .aspx goes to another). In the end, the user has no idea they are on two separate servers, cause they only see the site being served on one domain name.
Note:
1) You won't be able to share sessions (which I'm sure you're already aware of).
2) HAProxy doesn't handle https, so if you need https then you'll have to have something to handle https termination, such as nginx or haproxy or stunnel.
Hope this is applicable, because I'm not familiar with heroku.
域的 DNS 记录只能指向一个 IP 地址(以及服务器)。您可以配置基于 Heroku 的应用程序,通过有效地获取站点并显示它来呈现来自另一台服务器的内容。
我从此链接借用了此代码片段:
http://answers.oreilly.com/topic/1052-ruby-on-rails-how-does-one-render -html-from-another-web-server-to-a-ruby-on-rails-app/
对于任何这样的请求,性能可能会很差,因为它实际上会占用两个请求的时间。
The DNS record for the domain can only point to one IP address (and consequently server). You could configure your heroku based application to render content from another server by effectively fetching the site and displaying it.
I've borrowed this code snippet from this link:
http://answers.oreilly.com/topic/1052-ruby-on-rails-how-does-one-render-html-from-another-web-server-to-a-ruby-on-rails-app/
There will likely be poor performance to any request like this as it will effectively take the time of two requests.