Nginx proxy depending on the domain name

I’m using a EC2 from AWS with Nginx.

Let’s say I have three domain name:,,
Let’s also say that I have three rails application on three different port: 3000, 3001, 3002.

All of these domains are linked to my server on the port 80.

Depending on which URL is requested, I want my port 80 to redirect the request to the correct port.

How should I configure my virtual host file? I know that the If block exist but Nginx seem to not recommend it. My plan is to have multiple sites on my EC2.

I can’t make server block on my rails app port since it would block the rails server.


Leave a Reply