如何创建指向bluehost子文件夹的节点http代理?

时间:2015-05-09 17:04:57

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

我有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/或localnode为localhost的本地计算机上的http://localnode.com:3000/blog/

非常感谢这方面的帮助, 谢谢!

1 个答案:

答案 0 :(得分:0)

修改

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

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/看到您的博客,没有任何问题。

<强> /修改

您应该删除网址末尾的端口号:80。请尝试使用此网址:

http://69.195.124.88/~crowdfoo/blogbeaconboss/

请注意,端口应该附加到主机名,而不是像您拥有它之类的路径。如果您想指定端口,它将如下所示:

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

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