route different proxy based on subdomain request in nginx

前端 未结 3 1842
梦毁少年i
梦毁少年i 2020-12-07 13:01

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

I had

相关标签:
3条回答
  • 2020-12-07 13:10

    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.

    0 讨论(0)
  • 2020-12-07 13:14

    You can use RegExp to fetch host name like this

    server {
        server_name   ~^(www\.)?(?<domain>.+)$;
    
        location / {
            root   /sites/$domain;
        }
    }
    
    0 讨论(0)
  • 2020-12-07 13:20

    You can create virtual host for every sub domain.

    For Ex you have 2 sub domain abc.xyz.com and abcd.xyz.com , and you want to host it on nginx single instance by proxy_pass then you can simply create virtual host for every sub domain

    server {
      server_name abc.xyz.com;
      location / {
        proxy_pass http://127.0.0.1:8000;
      }
    }
    server {
      server_name abcd.xyz.com;
      location / {
        proxy_pass http://127.0.0.1:8000;
      }
    }
    

    For more information you can refer here

    0 讨论(0)
提交回复
热议问题