簡體   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