[英]Is it possible to create multiple Node.js HTTP servers, and access them via a request URL (not a subdomain)?
Let's say I had a few separate HTTP servers made in node, each with a unique ID attached to them. 假设我在节点中有几个单独的HTTP服务器,每个服务器上都附加了一个唯一的ID。 Is there any way to access them with request URLs based on that id?
有什么方法可以使用基于该ID的请求URL访问它们? For example:
例如:
Server ifjw48n: accessible via http://example.com/ifjw48n 服务器ifjw48n:可通过http://example.com/ifjw48n访问
Server ty58u7e: accessible via http://example.com/ty58u7e 服务器ty58u7e:可通过http://example.com/ty58u7e访问
It appears you can do this with nginx used as a routing proxy. 看来您可以将nginx用作路由代理来执行此操作。 Similar question in a different stackexchange forum answered here: Routing to various node.js servers on same machine .
在不同的stackexchange论坛中,类似的问题在这里回答: 路由到同一台机器上的各种node.js服务器 。
From that answer, here's a sample config that does routing based on the URL: 根据该答案,这是一个基于URL进行路由的示例配置:
server {
listen 80;
server_name example.com;
location /foo {
proxy_pass http://localhost:9000;
}
location /bar {
proxy_pass http://localhost:9001;
}
location /baz {
proxy_pass http://localhost:9002;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.