How to configure nginx so that the front and back ends of different ports of the same domain name can interact with each other.

now the front end of my project is react, the back end is ssm, front end in localhost:3000, and the back end is in localhost:8080,
, that is, how to transfer the request of localhost:3000 to localhost:8080,
how to correctly set the location of nginx
the following is my location configuration:

   server { 
   listen 80; 
   
   server_name  localhost;

    -sharpcharset koi8-r;

    -sharpaccess_log  logs/host.access.log  main;

    location / {
        root   html;
        index  index.html index.htm;  
    }

    -sharperror_page  404              /404.html;

    -sharp redirect server error pages to the static page /50x.html
    -sharp
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

    -sharp proxy the PHP scripts to Apache listening on 127.0.0.1:80
    -sharp
    location ~ \.json$ {
        proxy_pass http://localhost:8080;
    }

    -sharp pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    -sharp
    -sharplocation ~ \.php$ {
    -sharp    root           html;
    -sharp    fastcgi_pass   127.0.0.1:9000;
    -sharp    fastcgi_index  index.php;
    -sharp    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    -sharp    include        fastcgi_params;
    -sharp}

    -sharp deny access to .htaccess files, if Apache"s document root
    -sharp concurs with nginx"s one
    -sharp
    -sharplocation ~ /\.ht {
    -sharp    deny  all;
    -sharp}
}

!!

api fix the prefix for your request and change it yourself

location /api {
  proxy_pass  http://localhost:8080/api;
}
For more information, please see https://www.thinktxt.com/ngin.

.

set reverse proxy

Menu