在nginx中根据子域请求路由不同的代理 [英] route different proxy based on subdomain request in nginx

查看:17
本文介绍了在nginx中根据子域请求路由不同的代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在该服务器中有一台专用服务器,我部署了 5 个 nodejs 应用程序.

I have one dedicated server in that server I deployed 5 nodejs application.

domain name: www.nnd.com
dedicated server ip: xxx.xx.x.60

我有一个指向我的专用服务器 IP 的域.

I had domain which is pointed to my dedicated server ip.

子域是:

app1.nnd.com pointed to xxx.xx.x.60
app2.nnd.com pointed to xxx.xx.x.60
app3.nnd.com pointed to xxx.xx.x.60
app4.nnd.com pointed to xxx.xx.x.60
app5.nnd.com pointed to xxx.xx.x.60

现在在基于我需要路由代理的子域的 nginx 配置文件中.示例:

now in nginx configuration file based on the subdomain I need to route proxy. Example:

{
    listen:80;
    server_name:xxx.xx.x.60
    location / {
        #here based on subdomain of the request I need to create proxy_pass for my node application 
    }
}

有什么条件,如何从代理头中获取原始域名?

Is there any condition and how can I get the original domain name from proxy header?

推荐答案

为每个人创建一个虚拟主机

create a virtual host for each

server {
  server_name sub1.example.com;
  location / {
    proxy_pass http://127.0.0.1:xxxx;
  }
}
server {
  server_name sub2.example.com;
  location / {
    proxy_pass http://127.0.0.1:xxxx;
  }
}

继续,更改端口号以匹配正确的端口.

And go on, change the port number to match the right port.

这篇关于在nginx中根据子域请求路由不同的代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆