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.

  • Thank you for your answer. I did what you. I didn't have to change anything. Still, I am getting Ngxin's default page on port 80 and no redirections to port 3000 – ChiPlusPlus May 12 at 18:53
  • Works for me with the above config considering the file is saved as something.conf. Also check that you don't have the name server_name values for your default server config. – MagiiTech May 13 at 13:31

I am putting this answer in case someone faces the same issue as me. As said in the accepted answer, the proxy was correct. The root cause of the issue was from the fact that the subdomain took some time to take effect.

Also, if you want to serve react app static files directly from Nginx, here is a good tutorial .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.