2
我有一个基本的http服务器运行在多个域指向的服务器上。我需要找到请求的主机(请求来自的域)。从NodeJS请求获取主机
require("http").createServer(function (req, res) {
console.log(req.headers.host);
res.end("Hello World!");
}).listen(9000);
req.headers.host
的值是127.0.0.1:9000
代替域名(example.com
左右)。
如何从请求对象获取域名?
节点服务器通过nginx
代理。配置是这样的:
server {
listen 80;
server_name ~.*;
location/{
proxy_pass http://127.0.0.1:9000;
}
}
节点服务器如何代理? nginx的? – 2014-09-21 07:45:26
@JoachimIsaksson没错。 – 2014-09-21 07:46:44
@JoachimIsaksson不要忘了添加一个答案。问题解决了。 :-) – 2014-09-21 07:49:40