1

Have some development hosts we're trying to run Apache/PHP and Node.js on. Ideally simple ProxyPass for node services running against local port should work, but for some reason I need to supply local network IP, localhost gives 503 error.

$ cat nodeproxy.conf

<Directory /public/np1/site>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

<VirtualHost *:80>
    ServerName np1.local.zaptech.org
    DocumentRoot /public/np1/site

    ProxyRequests on
#   ProxyPass /np1/ http://localhost:1337/  <- doesn't work, 503 error
#   ProxyPass /np1/ http://127.0.0.1:1337/  <- doesn't work, 503 error
    ProxyPass /np1/ http://10.10.10.76:1337/
</VirtualHost>

$ cat sysd

[Unit]
Description=Node.js Example Server

[Service]
ExecStart=/bin/node /home/rickatech/node/example.js
Restart=always
RestartSec=10                       # Restart service after 10 seconds if node service crashes
StandardOutput=syslog               # Output to syslog
StandardError=syslog                # Output to syslog
SyslogIdentifier=nodejs-ricktest
User=rickatech
Environment=NODE_ENV=production PORT=1337

[Install]
WantedBy=multi-user.target
rickatech
  • 141
  • 8
  • What error message do you get when you use wget to connect to the localhost url ? `Connection Refused` ? – user9517 Sep 07 '16 at 19:04
  • Possible duplicate of [What causes the 'Connection Refused' message?](http://serverfault.com/questions/725262/what-causes-the-connection-refused-message) – user9517 Sep 07 '16 at 19:25

2 Answers2

2

The simple answer would be that the service running on port 1337 is only bound to the primary IP address and not localhost, you can use netstat, lsof or similar to find out.

I do not know node.js, but I'm sure a quick search will find posts telling you how to make node.js bind to localhost if it is not.

One quick note, you should always match trailing slashes in your ProxyPass (and ProxyPassReverse) directives. So for example

ProxyPass /np1/ http://localhost:1337/
or
ProxyPass /np1 http://localhost:1337

instead of

ProxyPass /np1 http://10.10.10.76:1337/
or
ProxyPass /np1/ http://10.10.10.76:1337

Normally, unless there is a specific reason not to, you should have trailing slashes on both.

Unbeliever
  • 2,336
  • 1
  • 10
  • 19
  • Trailing / thanks, I fixed the original post. Still befuddled by why only localhost returns 503 error. – rickatech Sep 07 '16 at 18:49
  • Well 503 means no connection could be made at all, which is why I suggest node.js may not be listening on 127.0.0.1, only on the primary IP. – Unbeliever Sep 07 '16 at 18:51
0

Ah, the rabbit hole goes a bit deeper on this ...

$ cat example.js

var http = require('http');

http.createServer(function (req, res) {
    res.writeHead(200, {
        'Content-Type': 'text/plain'
        });
    res.end('Hello World\n');
    }).listen(1337, "10.10.10.76");  //  change this to 127.0.0.1 !

Port is in the javascript, not sure why sysd needs the PORT directive at all.

rickatech
  • 141
  • 8