在不同的服务器上托管博客?

发布于 2024-08-14 09:12:26 字数 173 浏览 2 评论 0原文

目前,我的公司博客与我们的主网络应用程序位于同一服务器上 - 如 example.com/blog

将博客移动到不同服务器但仍允许用户访问的最简单方法是什么博客位于 example.com/blogblog.example.com

Currently I have my companies blog on the same server as our main web app - as in example.com/blog

What would be the easiest way to move the blog to a different server yet still let users either access the blog at example.com/blog or blog.example.com?

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

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

发布评论

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

评论(5

孤独岁月 2024-08-21 09:12:26

问题 301 HTTP 从 website.com/blog 重定向到 blog.website.com

具体取决于服务器。

Issue 301 HTTP redirects from website.com/blog to blog.website.com

The specifics depend on the server.

微凉徒眸意 2024-08-21 09:12:26

我提供的答案是假设您使用 Apache 作为网络服务器,因为这是我所熟悉的。如果您使用 IIS,那么您也许能够找到类似的解决方案,但我不能保证这一点。

过去,我遇到过类似的问题,客户将其主网站托管在 www.mydomain.com,但他们的博客由营销人员托管在 blog.mydomain.com。出于 SEO 目的,将博客显示在 www.mydomain.com/blog 上可能会有所帮助,尽管由于 DNS 协议的性质,这在物理上是不可能的。

答案是使用名为 mod_proxy 的 Apache 模块,它允许您将 url /blog 映射到子域,这对于最终用户(更重要的是搜索引擎)是不可见的。 CodeHaus 发表了一篇关于配置 mod_proxy 的好文章(2016 年更新:链接无处可去),你可能想读一读。

mod_proxy 非常复杂,可能需要一段时间才能正确设置,但它是迄今为止解决您所描述问题的最佳解决方案。

The answer that I provide is assuming that you are using Apache as the webserver as this is what I am familiar with. If you are using IIS then you may be able to find a similar solution but I cannot guarantee this.

In the past I have come across similar issues, whereby a client is hosting their main website at www.mydomain.com but their blog is hosted by their marketing guys at blog.mydomain.com. For SEO purposes it ca be beneficial to have the blog appear at www.mydomain.com/blog although this is not physically possible due to the nature of DNS protocols.

The answer is to use an Apache module called mod_proxy which allows you to map the url /blog to a subdomain and this is invisible to the end-user and, more importantly, search engines. CodeHaus have published a good article on Configuring mod_proxy (update 2016: link leading nowhere) and you may like to have a read.

mod_proxy is quite complex and it can take a while to get the settings correct but it is by far the best solution to the problem that you describe.

青萝楚歌 2024-08-21 09:12:26

您可以使用简单的 JavaScript 重定向代码(如下所示)来重定向用户。

<script type="text/javascript">
<!--
window.location = "http://www.example.com/";
//-->
</script>

You can use a simple javascript redirect code such as the one below to redirect the user.

<script type="text/javascript">
<!--
window.location = "http://www.example.com/";
//-->
</script>
記憶穿過時間隧道 2024-08-21 09:12:26

您是在自己的数据中心托管这些服务器,还是购买托管服务?我们的公司网站托管在数据中心的多台服务器上。我们使用负载均衡器根据 URL 将流量路由到不同的服务器场。因此

http://www.foo.com/assets/* 可能会路由到 Apache HTTP 场仅提供图像文件的服务器,而

http://www.foo.com/apps/* 可能路由到 JEE 应用程序服务器场和

http://www.foo.com/services/* 的服务器场

可能会路由到专门设计用于托管 Web 服务和http://www.foo.com/blog/ * 可能会路由到一个只处理 WordPress 的服务器场。

效果很好...如果您可以使用所有这些。如果你不这样做,那么请像 Matt 所说的那样检查 mod_proxy (我们在购买负载均衡器之前使用过它)。

Are you hosting these servers in your own data center, or are you purchasing hosting? Our corporate site is hosted on multiple servers in our data center. We use load balancers to route traffic to different server farms based upon the URL. So

http://www.foo.com/assets/* might route to a farm of Apache HTTP servers that serve nothing but image files while

http://www.foo.com/apps/* might route to a farm of JEE application servers and

http://www.foo.com/services/* might route to a farm of servers especially designed to host web services and

http://www.foo.com/blog/* might route to a farm of servers that handle nothing but WordPress.

Works great... if you have all of this at your disposal. If you don't, then check out mod_proxy like Matt said (which we used before we bought load balancers).

嘿看小鸭子会跑 2024-08-21 09:12:26

blog.example.com

blog.example.com 最简单,因为您只需将其指向不同的 IP 地址即可。

对于我正在从事的项目来说,这不是我想要的。

example.com/blog

相反,我使用 Apache mod_proxy/blog 指向另一台服务器。 Apache 文档此处

这运作良好:

ProxyPass /blog http://blog.example.com/
ProxyPassReverse /blog http://blog.example.com/

但只有在正确加载代理模块之后:

LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_html_module /usr/lib/apache2/modules/mod_proxy_html.so
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so

注释

  • 由于 CloudFlare,我还必须从不同的主机名(而不是 *.example.com)托管博客。
  • 我将 Disallow: / 添加到我的 blog.example.com/robots.txt 中。像这样,搜索引擎不会在两个位置开始索引。搜索引擎将简单地忽略 blog/robots.txt

blog.example.com

blog.example.com is easiest, since you can simply point it to a different IP address.

That is not what I want for a project I'm working on.

example.com/blog

Instead I use Apache mod_proxy to point /blog to another server. Apache docs here.

This worked well:

ProxyPass /blog http://blog.example.com/
ProxyPassReverse /blog http://blog.example.com/

But only after the proxy modules were loaded correctly:

LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_html_module /usr/lib/apache2/modules/mod_proxy_html.so
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so

Notes

  • Because of CloudFlare I also had to host the blog from a different hostname, not *.example.com.
  • I added Disallow: / to my blog.example.com/robots.txt. Like this search engines will not start indexing in two locations. And search engines will simply ignore blog/robots.txt.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文