【问题标题】:How to create node http proxy pointing to bluehost subfolder?如何创建指向 bluehost 子文件夹的节点 http 代理?
【发布时间】:2015-05-09 17:04:57
【问题描述】:

我有一个blog here

这就是我所做的:

var httpProxy = require('http-proxy'); 
var apiProxy = httpProxy.createProxyServer();

app.get("/blog/", function(req, res){ 
    apiProxy.web(req, res, { target: 'http://69.195.124.88/~crowdfoo/blogbeaconboss/:80' });
});

但它说:

404:找不到文件

当我打开时: http://www.example.com/blog/ 用于生产或http://localnode.com:3000/blog/ 在本地节点为 localhost 的本地机器上

不胜感激, 谢谢!

【问题讨论】:

  • 只是为了确定,您是否将 www.example.com 指向 localhost,这就是您使用 www.example.com 的原因吗?
  • @JosefEngelfrost,更新了问题以澄清这一点。

标签: node.js wordpress http-proxy node-http-proxy


【解决方案1】:

编辑:

我认为部分问题可能是您试图在代理 URL 中包含路径。我试过这个:

var express = require('express');
var app = express();
var httpProxy = require('http-proxy');
var apiProxy = httpProxy.createProxyServer();

app.use('/', function(req, res) {
    apiProxy.web(req, res, {
        target: 'http://69.195.124.88'
    });
});

app.listen(3000, function() {
    console.log('listening');
});

现在我可以在http://localhost:3000/~crowdfoo/blogbeaconboss/ 看到你的博客,没有任何问题。

/编辑

您可能应该删除 URL 末尾的端口号 :80。试试这个网址:

http://69.195.124.88/~crowdfoo/blogbeaconboss/

请注意,端口应该附加到主机名,而不是像您拥有的路径之后。如果你想指定端口,它看起来像这样:

http://69.195.124.88:80/~crowdfoo/blogbeaconboss/

但这是多余的,http URL 方案意味着如果未指定,则使用端口 80。

【讨论】:

  • 试过没有端口和主机名后有端口,仍然是 404 :(
  • Re:edit 问题是这个IP上托管了多个博客,它们位于子文件夹中
猜你喜欢
  • 2017-02-28
  • 1970-01-01
  • 1970-01-01
  • 2021-02-06
  • 2019-12-13
  • 2013-08-23
  • 1970-01-01
  • 1970-01-01
  • 2021-03-02
相关资源
最近更新 更多