首页 > 解决方案 > 通过 ngnix 在 Ubuntu VPS 上部署 .Net Core 和 Angular 作为 SPA

问题描述

我正在尝试将应用程序扔到 VPS(Ubuntu)上。这是一个 .Net Core + Angular 应用程序。我想用ngnix服务它。我将应用程序合并为一个。当然,在 angular.json 文件中的 Angular 应用程序中,我将 outputPath 变量设置为 API 并启动它。总的来说是。启动 API dll 后,一切都开始正常,即您可以看到 Angular 应用程序的开始屏幕,但如果我想做一些需要 API 查询的事情(例如登录),它就不起作用。所以,简而言之,前端不能和API结合。但是,如果我输入我的IP 147.135.xxx.xxx/Client/4,即我手动询问API,没有问题,一切正常。总的来说,检查邮递员 API 没有任何问题。问题是前端没有连接到后端。在本地主机上,http://147.135.xxx.xxx进入浏览器以显示应用程序启动屏幕,这与 localhost:5000 完全相同。以前,前端有一个 localhost,可以说是 4200,而它们尚未连接。Cors 设置为我的 IP。更多信息。Ngnix 配置文件如下。

server {
       listen 80;
       server_name _;
        
       
location / {
         proxy_pass http://127.0.0.1:5000;       
       proxy_http_version 1.1;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection keep-alive;
       proxy_set_header Host $host;
       proxy_cache_bypass $http_upgrade;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $scheme;
       }

location /Client/ {    
           proxy_pass http://127.0.0.1:5000;       
       proxy_http_version 1.1;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection keep-alive;
       proxy_set_header Host $host;
       proxy_cache_bypass $http_upgrade;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $scheme;       
}

location /Auth {    
           proxy_pass http://127.0.0.1:5000;       
       proxy_http_version 1.1;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection keep-alive;
       proxy_set_header Host $host;
       proxy_cache_bypass $http_upgrade;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $scheme;       
}

location /Register {    
           proxy_pass http://127.0.0.1:5000;       
       proxy_http_version 1.1;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection keep-alive;
       proxy_set_header Host $host;
       proxy_cache_bypass $http_upgrade;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $scheme;       
}


}

标签: c#angularubuntunginx

解决方案


推荐阅读