我正在尝试配置 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)