Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Update July 28 2015:</strong> this answer has now been incorporated into the official Passenger documentation. Please refer to <a href="https://www.phusionpassenger.com/library/indepth/nodejs/reverse_port_binding.html" rel="nofollow">https://www.phusionpassenger.com/library/indepth/nodejs/reverse_port_binding.html</a> for the latest answer.</p> <hr> <p>Phusion Passenger author here. First, let me explain what why this error occurs.</p> <p>As explained in <a href="https://github.com/phusion/passenger/wiki/Phusion-Passenger:-Node.js-tutorial" rel="nofollow">the Node.js tutorial</a>, Phusion Passenger <a href="https://github.com/phusion/passenger/wiki/Phusion-Passenger:-Node.js-tutorial#wiki-port_binding" rel="nofollow">inverses port binding</a> by hooking into <code>http.Server.listen()</code>. If there are multiple <code>listen()</code> then Passenger doesn't know which http.Server object to use for receiving requests, so it throws this error.</p> <p>To solve this problem, you need to tell Passenger "I want to specify explicitly which http.Server to use for receiving requests". This is done in two steps. First, you must call the following code as early as possible in your program:</p> <pre><code>if (typeof(PhusionPassenger) != 'undefined') { PhusionPassenger.configure({ autoInstall: false }); } </code></pre> <p>Next, you need to modify one (and only one) invocation of <code>http.Server.listen()</code>, and make it pass <code>'passenger'</code> s argument:</p> <pre><code>server.listen('passenger'); </code></pre> <p>If Passenger notices that you have multiple <code>listen('passenger')</code> calls, it will complain. You can only have one.</p> <p>Since Phusion Passenger 4.0.52 you can also pass <code>'/passenger'</code> as argument. This is intended for Hapi.js support (see below).</p> <h2>Express.js example</h2> <p>Here is a full example utilizing the Express framework. You must pass <code>'passenger'</code> to Express's <code>listen()</code> call.</p> <pre><code>if (typeof(PhusionPassenger) != 'undefined') { PhusionPassenger.configure({ autoInstall: false }); } var express = require('express'); var app = express(); app.get('/', function(req, res){ var body = 'Hello World'; res.setHeader('Content-Type', 'text/plain'); res.setHeader('Content-Length', body.length); res.end(body); }); if (typeof(PhusionPassenger) != 'undefined') { app.listen('passenger'); } else { app.listen(3000); } </code></pre> <h2>Hapi.js example</h2> <p>When using Hapi.js, you must pass <code>'/passenger'</code> (not <code>'passenger'</code>) to Hapi's server constructor. This will cause Hapi try to listen on a Unix domain socket, which allows Phusion Passenger's overrides to kick in. If you do not pass that initial slash, then Hapi will try to treat the argument as a TCP/IP domain name, and Hapi will fail with an error.</p> <pre><code>if (typeof(PhusionPassenger) != 'undefined') { PhusionPassenger.configure({ autoInstall: false }); } var Hapi = require('hapi'); var server; if (typeof(PhusionPassenger) != 'undefined') { // Requires Phusion Passenger &gt;= 4.0.52! server = new Hapi.Server('/passenger'); } else { server = new Hapi.Server('localhost', 3000); } server.route({ method: 'GET', path: '/hello', handler: function (request, reply) { reply('hello world'); } }); server.start(); </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