我想使用 nginx 在 phusion guest 上执行一个简单的 node-http-proxy 示例。您可以在https://github.com/nodejitsu/node-http-proxy上找到此示例代码。
var http = require('http'),
httpProxy = require('http-proxy');
//
// Create your proxy server
//
httpProxy.createServer(9000, 'localhost').listen(8000);
//
// Create your target server
//
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2));
res.end();
}).listen(9000);
Run Code Online (Sandbox Code Playgroud)
如果我执行这段代码,我会收到以下错误。
App 28096 stderr: /usr/share/passenger/helper-scripts/node-loader.js:157
App 28096 stderr: throw new Error("http.Server.listen() was called more than once, which " +
App 28096 stderr: ^
App 28096 stderr: Error: …Run Code Online (Sandbox Code Playgroud)