c# - 通过 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# - Polly 使用不同的请求体重试请求
- c# - C# AspNet.Core 请求查询 -> EF Core 谓词表达式
- android - PrintDocumentAdapter 不能为空,当我试图在 android studio 中打印现有的 pdf 文件时
- postgresql - 从列中获取特定字符串,然后需要与 postgresql 中其他表中的列进行比较
- flutter - Flutter项目中的包冲突
- amazon-web-services - AWS EC2 预留实例
- python - 如何防止 Django 管理员删除确认视图显示所有要删除的对象?
- reactjs - 为反应折叠组件添加默认打开逻辑
- php - 如何为“Illuminate\Support\ItemNotFoundException”返回自定义响应?
- angular - Angular typescript 在将子类实现为抽象类时给出参考错误