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

查看:211
本文介绍了根据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天全站免登陆