React static files call request from express Nginx

I have a remote server machine, and i have nginx serves react app as static files in my server, it works well using remote ip. What i want to do is run express backend in my server and when my react app call request to that express, it call from localhost server, because they in the same machine, is that posible?

I did some research on google and end up with this nginx configuration

upstream backend {
  server localhost:5000;

server {
  listen 8015;

  location / {
    root /var/www/my-domain; #Here is my react static files
    try_files $uri /index.html =404;

  location /auth/isVerify { #Here is my attempt to call express via localhost
    proxy_pass http://localhost:5000/auth/isVerify;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;

BUT, if i run express on my pc machine the request works very well, why is that? React app runs on remote server but calling request from localhost pc machine.

Any idea? Solution? Help?

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer