Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

route different proxy based on subdomain request in nginx

Tags:

nginx

proxy

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 domain which is pointed to my dedicated server ip.

sub domains are :

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 

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?

like image 338
sridhar Avatar asked Jan 11 '14 15:01

sridhar


People also ask

What is reverse proxy?

A reverse proxy server is a type of proxy server that typically sits behind the firewall in a private network and directs client requests to the appropriate backend server. A reverse proxy provides an additional level of abstraction and control to ensure the smooth flow of network traffic between clients and servers.


1 Answers

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.

like image 95
Mohammad AbuShady Avatar answered Oct 24 '22 14:10

Mohammad AbuShady