繁体   English   中英

nginx 与 node.js 的设置

[英]Setup of nginx with node.js

我已将 nginx 设置为 node.js 应用程序的前端。

我的 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;
    }
  }
}

我的 node.js 应用程序是:

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

当我发出:

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

我收到一个错误,而不是代理到我的 node.js 应用程序。

任何想法?

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

如果您有节点在特定端口上侦听,并且 proxy_pass 到http://127.0.0.1:{that_port} ,它是否有效? (假设两者都在同一台服务器上......)

暂无
暂无

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

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