-1

I am new to NgInx. I don't know i have to ask or not but step forward and i need it for my application redirection. I have 2 Asp.net web applications and based on domain and context path i need to redirect to particular application.

app1

env.example.com:9060

app2

env.example.com:9040

for example

Step1: if i hit this given url in browser any one application should redirect

domain Url1: abc.example.com

domain url2: xyz.example.com

Step2 if i hit this given url in browser with context path then crossponding application should redirect

domain Url1: abc.example.com/app1==>redirect to app1

domain url2: xyz.example.com/app2==>redorect to app2

Looking for server listen and location directive setting etc etc config Any help is very much appriciated.

Thanks.

cj devin
  • 1,045
  • 3
  • 13
  • 48

1 Answers1

2

From what I gather you want something like this

default_server Routes all non-matched connections see more

server_name abc.example.com xyz.example.com; Accepts either URL see more

location /app1 Defines a specific route for the desired server see more

server {
     listen 80 default_server; # This allows any
     listen [::]:80 default_server; 

     listen 443;
     listen [::]:443;

     server_name abc.example.com xyz.example.com;

     location /app1 { 
         proxy_pass env.example.com:9060;
     }

     location /app2 {
         proxy_pass env.example.com:9040;
     }
}
flyingscot5
  • 84
  • 2
  • 13
  • currently i have two domain but in future no of domains more so there `server_name abc.example.com xyz.example.com;` i don't want to specify – cj devin Oct 24 '20 at 06:36
  • Then remove `server_name` option and just have `default_server` this will allow all domains to work – flyingscot5 Oct 24 '20 at 09:32
  • ok thanks..in above facing one ssue like in browser hit `https://abc.example.com/app1/home/username` and `app1` from url automatically got removing and it's becoming `https://abc.example.com/home/username`.. – cj devin Oct 24 '20 at 11:22
  • Not sure what your issue is, but if you want the URL to be the same you can do `location /app1 { proxy_pass env.example.com:9060/app1; }` – flyingscot5 Oct 24 '20 at 15:20