1

I have setup nginx as a front end to an node.js app.

My nginx conf is:

worker_processes  1;
error_log  /tmp/logs/error.log;
events {
  worker_connections  1024;
}

http {
  include       mime.types;
  default_type  application/octet-stream;
  access_log  /tmp/logs/access.log;
  sendfile        on;
  keepalive_timeout  65;

  include /etc/nginx/sites-enabled/*;

  # BELOW IS THE PART TO PROXY MY NODE.JS APP

  upstream node_entry {
    server unix:/tmp/express.sock
    fail_timeout=0;
  }
  server {
    listen 8888;
    client_max_body_size 4G;
    server_name localhost;

    keepalive_timeout 5;

    location / {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;
      proxy_pass http://node_entry;
    }
  }
}

My node.js app is:

express = require('express');
app = express.createServer();
app.get('/test', function(req, res){
  res.send('TEST');
});
app.listen('/tmp/express.sock'); 

When I issue a:

curl -XGET 'http://localhost:8888/test'

I get an error instead of proxying to my node.js app.

Any idea ?

1 Answer 1

1

I'm doing something similar, but it's all on one host, and I'm using a predefined port number that nginx and node both know (though I'd rather use your way if you can get it working).

Does it work if you have node listen on a specific port, and proxy_pass to http://127.0.0.1:{that_port}? (assuming both are on the same server...)

Sign up to request clarification or add additional context in comments.

3 Comments

You might check into the socket permissions as well, per this article: william.shallum.net/random-notes/… var http = require("http"); var oldUmask = process.umask(0000); var server = http.createServer(function(request, response) { // ... }); server.listen("/some/socket/path", function() { process.umask(oldUmask); });
I'll check this but as I use /tmp I though I should not have any problem with rights.
Thanks, after I executed: chmod o+w /tmp/xxx.sock, it works!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.