How to redirect connection from subdomain to another server using Nginx

I am working on an app where I have a following elemnts:

  • A subdomain name redirected to port 80 of server A
  • Server A hosting two docker containers: one for nginx mapping port 80 to 80 and one for a react app mapping port 3000 to 3000.

What I want to do is simple: I want to redirect using nginx connection coming the subdomain to port 3000 and thus display the react app.

To do that I am using this file I am putting in /etc/nginx/sites-enabled/. For the moment, when I connect to my_domain.com, I have the default page for nginx, no redirection to ip_address:3000 .

server {
listen 80;

server_name my_subdomain www.my_subdomain.com;
location /{
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://ip_address:3000;
}


}

Your proxy looks correct, considering you are connecting to www.my_subdomain.com and not connecting via https. You should verify that your config is being loaded, I remember some nginx servers only load sites-enabled/*.conf, check /etc/nginx/nginx.conf for the line:

include /etc/nginx/sites-enabled/*.conf;

Also a react app is only some static files, so you can let them be served by nginx directly, there no need for proxying it.