StayCool
StayCool

Reputation: 552

can't serve port 80 express.js reverse proxy nginx

Ubuntu 14.04. Losing my mind attempting to serve an app on port 80 using nodejs/expressjs. At first I received an "Error: listen EACCESS" error (program exits). This was solved on my local machine by running node as sudo.

On my Linux host, however, even sudo won't prevail, and I get "listen EADDRINUSE" (program exits). Here expressjs is reverse proxied with nginx.

Higher numbered ports don't have any problems (e.g. default 3000)

Abridged version of the node app:

var express = require('express');
var app = express();

var myPort = 80;

app.listen(port, function() {
    console.log("listening on " + parseInt(myPort) + "...");
});

NGINX config

server {
    listen 80;
    listen [::]:80;

    server_name devjustice.com www.devjustice.com;
    location / {
            proxy_pass http://127.0.0.1:80;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
            try_files $uri $uri/ =404;
}

Can't for the life of me think of what's already occupying this address? nginx is serving other config files but nothing (it seems?) that touches the loopback address or uses the same domain name. Thanks for any help. Similar issues are touched upon on other SO posts but I wasn't able to find a solution.

Upvotes: 0

Views: 366

Answers (1)

mscdex
mscdex

Reputation: 106698

You have two processes trying to listen on the same port, which won't work (at least without using SO_REUSEPORT, but that wouldn't make sense in this scenario). Just choose a different port for node and adjust your nginx configuration accordingly.

Upvotes: 1

Related Questions