0

I looked at this question, but nothing helped. I'm trying to configure localhost:3000 to be proxied to port 80. Here's my nginx config (located in sites-enabled and sites-available):

server {
    listen 0.0.0.0:80;
    server_name fit-forms;
    access_log /var/log/nginx/fit-forms.log;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header HOST $http_host;
        proxy_set_header X-NginX-Proxy true;

        proxy_pass http://localhost:3000;
        proxy_redirect off;
    }
}

I get Cannot GET / when I visit the IP (this is on DigitalOean). None of the static files show up. Here's my express code:

var express = require('express'),
  livereload = require('connect-livereload'),
  config = require('./config'),
  app = express(),
  env = app.get('env'),
  port = process.env.PORT || config.serverPort || 3000;

if (env === 'development') {
  app.use(livereload());
  app.use(express.logger('dev'));
  app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
}

app.use(express.compress());
app.use(express.urlencoded());
app.use(express.json());

app.use(express.static(__dirname + '/public'));

app.listen(port);
console.log('Express server (' + env + ') running on port ' + port);

I'm assuming my nginx config is lacking..

Community
  • 1
  • 1
knownasilya
  • 5,998
  • 4
  • 36
  • 59

1 Answers1

1

I had the same situation.

The key is in this value:

__dirname + '/public'

Just try to output it e.g.

res.send(__dirname + '/public')

and you will probably will see the origin of the issue.

In my case the category of the nodejs app and the public_html directory were on the same level and the nodejs script was unable to find it.

So I changed it this way:

__dirname + '/../public'
agronom413
  • 71
  • 1
  • 3