0

I have a EC2 instance on which I am running a React App and a domain from Route 53, for example xyz.com.

For this xyz.com I have two subdomains say www.xyz.com and demo.xyz.com.

Now, traditionally my React App serves on PORT 3000 on this instance. I have configured the IP with the PORT using nginx on my instance, something like this 192.1.1:3000. Now whenever I hit this domain (www.xyz.com) I am redirected to 192.1.1:3000.

For example, if I have two versions of my app called dev and prod. dev serves on PORT 3000 and prod serves on PORT 3002.

I want to www.xyz.com to redirect to 3000 and demo.xyz.com redirect to 3002. Both of these are from the same DNS provider.

Is there a away to achieve this?

vaibhav deep
  • 655
  • 1
  • 8
  • 27

1 Answers1

0

try this way:

 server {
        server_name www.xyz.com;
        location / {
            proxy_pass       http://192.1.1:3000;
        }
 }
 server {
        server_name demo.xyz.com;
        location / {
            proxy_pass       http://192.1.1:3002;
        }
 }

( add extra parameters if you want to add regarding the request, header etc )

I hope this answer helps you.
Feel free to comment if you get any errors in this and don't forget to mention the answer as accepted if it works. It'll help the others who is looking for the silimar answer.

sachin
  • 1,075
  • 1
  • 7
  • 11