After the react agent is deployed, access 404

problem description:
1.react implements a dynamic proxy in package.json, as follows:

 "proxy": "http://www.iamcrawler.cn:4000"

2. When you get up locally, you can access it.
3. After packaging with run build, put it in the corresponding directory and configure the nginx mapping. The nginx mapping is as follows:

server {
    listen       3002 ;
    
    -sharp Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    root /react/build;

    location / {
      try_files  $uri $uri/ /index.html;
    }
    error_page 404 /404.html;
        location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }
         
  
}

4. But when accessing the server www.iamcrawler.cn:3002, the page can come out, but the interface throw 404 can not find the path, is there a problem with my nginx configuration?

Mar.22,2021

nginx is only configured with static pages that can be accessed through 3002, but there is no interface mapping configured.
if all interfaces are accessed through / api, the following configuration should be added to the nginx

upstream backend {
    server xxx.xxx.xxx.xxx:4000 // ip
}
server {
    ....
    location /api {
       proxy_pass http://backend
    }
}
Menu