小编Mar*_*son的帖子

如何配置 nginx 使其与 Express 一起使用?

我正在尝试配置 nginx,以便它proxy_pass向我的节点应用程序发出请求。关于 StackOverflow 的问题得到了很多赞成:https ://stackoverflow.com/questions/5009324/node-js-nginx-and-now ,我正在使用那里的配置。

(但由于问题是关于服务器配置,它应该在 ServerFault 上)

这是nginx配置:

server {
  listen 80;
  listen [::]:80;

  root /var/www/services.stefanow.net/public_html;
  index index.html index.htm;
  server_name services.stefanow.net;

  location / {
    try_files $uri $uri/ =404;
  }

  location /test-express {
    proxy_pass    http://127.0.0.1:3002;
  }    

  location /test-http {
    proxy_pass    http://127.0.0.1:3003;
  }
}
Run Code Online (Sandbox Code Playgroud)

使用普通节点:

var http = require('http');

http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(3003, '127.0.0.1');

console.log('Server running at http://127.0.0.1:3003/');
Run Code Online (Sandbox Code Playgroud)

有用! 检查:http : //services.stefanow.net/test-http

使用快递:

var express = require('express');
var app = …
Run Code Online (Sandbox Code Playgroud)

nginx reverse-proxy http-headers node.js

14
推荐指数
1
解决办法
4万
查看次数

标签 统计

http-headers ×1

nginx ×1

node.js ×1

reverse-proxy ×1