Note that there are some explanatory texts on larger screens.

plurals
  1. POPhusion Passenger Error: http.Server.listen() was called more than once
    text
    copied!<p>I want to execute a simple node-http-proxy example on phusion passenger with nginx. You can find this example code on <a href="https://github.com/nodejitsu/node-http-proxy" rel="nofollow">https://github.com/nodejitsu/node-http-proxy</a>.</p> <pre><code>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); </code></pre> <p>If I execute this code, I get the following error.</p> <pre><code>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: http.Server.listen() was called more than once, which is not allowed because Phusion Passenger is in auto-install mode. This means that the first http.Server object for which listen() is called, is automatically installed as the Phusion Passenger request handler. If you want to create and listen on multiple http.Server object then you should disable auto-install mode. </code></pre> <p>Than I find a post on google groups <a href="https://groups.google.com/forum/#!topic/phusion-passenger/sZ4SjU8ypwc" rel="nofollow">https://groups.google.com/forum/#!topic/phusion-passenger/sZ4SjU8ypwc</a> and add</p> <pre><code>PhusionPassenger.configure({ autoInstall: false }); </code></pre> <p>before I call the first time "createServer(...).listen(port)".</p> <p>The next step was to replace the value of the port parameter of the listen-method with the value 'passenger'. But I have no success. Has anybody managed to get this to run? </p> <p>--- My solution ---</p> <p>Thank you Hongli for the advice "Next, you need to modify one (<strong>and only one</strong>) invocation ...". This solved my problem.</p> <pre><code>var http = require('http'), httpProxy = require('http-proxy'); if (typeof(PhusionPassenger) != 'undefined') { PhusionPassenger.configure({ autoInstall: false }); } httpProxy.createServer(9000, 'localhost').listen('passenger'); var 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); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload