简体   繁体   English

nginx 与 node.js 的设置

[英]Setup of nginx with node.js

I have setup nginx as a front end to an node.js app.我已将 nginx 设置为 node.js 应用程序的前端。

My nginx conf is:我的 nginx 配置是:

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:我的 node.js 应用程序是:

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' curl -XGET 'http://localhost:8888/test'

I get an error instead of proxying to my node.js app.我收到一个错误,而不是代理到我的 node.js 应用程序。

Any idea?任何想法?

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).我正在做类似的事情,但它都在一个主机上,并且我使用的是 nginx 和节点都知道的预定义端口号(尽管如果你能让它工作,我宁愿使用你的方式)。

Does it work if you have node listen on a specific port, and proxy_pass to http://127.0.0.1:{that_port} ?如果您有节点在特定端口上侦听,并且 proxy_pass 到http://127.0.0.1:{that_port} ,它是否有效? (assuming both are on the same server...) (假设两者都在同一台服务器上......)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM