【问题标题】:How can I proxy Wordpress with node-http-proxy, my wordpress redirects to a different port如何使用 node-http-proxy 代理 Wordpress,我的 wordpress 重定向到不同的端口
【发布时间】:2013-02-28 03:29:30
【问题描述】:

我想代理托管在 localhost 的 8888 端口的 Wordpress。

当我按如下方式 http://localhost:8001/ 访问此节点-http-proxy 时,它会重定向到 http://localhost:8888/。我的意思是 Wordpress 会进行重定向,因为 Wordpress 认为它​​在端口 8888 上。

我怎样才能正确地反向代理?

var util = require('util'),
    http = require('http'),
    httpProxy = require('http-proxy');

//
// Create a new instance of HttProxy to use in your server
//
var proxy = new httpProxy.RoutingProxy();

http.createServer(function (req, res) {
  proxy.proxyRequest(req, res, {
    host: 'localhost',
    port: 8888
  });
}).listen(8001);

这个问题有帮助吗? https://github.com/nodejitsu/node-http-proxy/pull/376 但是不明白怎么用。

【问题讨论】:

  • 您找到解决方案了吗?我正在尝试使用 nginx 作为反向代理进行类似的设置,而 WordPress 重定向正在搞砸一切。

标签: node.js node-http-proxy


【解决方案1】:

在 wp-config.php 中定义 WP_SITEURLWP_HOME 指向代理 url。

例如,

define('WP_SITEURL', 'http://example.com/blog/');
define('WP_HOME', 'http://example.com/blog/');

【讨论】:

    【解决方案2】:

    我怀疑您需要进入您的 wordpress 管理设置并将站点 URL 参数设置为 http://localhost:8001

    【讨论】:

    • 谢谢,但这不是我想做的,这可以工作,但是...我希望反向代理解决它
    • 请记住,反向代理不会修复 wordpress 在您的 HTML 中粘贴的任何绝对 URL。同样适用于 RSS 提要。基本上,我认为最终你将无法让这个代理对 wordpress 100% 透明。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-11
    • 1970-01-01
    • 2013-09-14
    • 2014-01-03
    • 1970-01-01
    相关资源
    最近更新 更多