Ubuntu Nginx-在不同端口中运行后端和前端

Ubuntu Nginx-在不同端口中运行后端和前端,ubuntu,nginx,reverse-proxy,Ubuntu,Nginx,Reverse Proxy,我有一个在3000端口运行的前端和一个在5000端口运行的后端。我的前端项目是react项目。我从ubuntu服务器启动react应用程序,然后在localhost:3000上启动。我在我的前端应用程序中使用了以下服务器块,它工作得非常好 server { listen 80 default_server; listen [::]:80 default_server; server_name servername.com www.servername.com; locat

我有一个在3000端口运行的前端和一个在5000端口运行的后端。我的前端项目是react项目。我从ubuntu服务器启动react应用程序,然后在localhost:3000上启动。我在我的前端应用程序中使用了以下服务器块,它工作得非常好

server {
  listen 80 default_server;
  listen [::]:80 default_server;
  
  server_name servername.com www.servername.com;

  location / {
    proxy_pass http://localhost:3000;
  }
}
我的后端是在端口5000中运行的dotnet

dotnet run --urls=http://localhost:5000/
在我的前端有一个API调用

http://localhost:5000/api/getNumbers
但我在那个api调用中发现了一个连接被拒绝错误

ERR_CONNECTION_REFUSED
我是否需要将后端托管在一个单独的服务器上,还是可以将同一个服务器用于后端和前端