[英]hosting two apps by nginx frontend and api
我正在尝试在 nginx 上托管我的 Angular 应用程序和我的 .net 核心应用程序,但我的配置有问题。 我的想法是当用户将 go 到页面(例如输入我的 IP 编号 147.135.xxx.xxx)将被重定向到端口 4200。这是我的 ZD18B8624A0F5F72DDZ 应用程序。 但是,我的 net.core 应用程序将在 vps 上本地运行,我希望它在 localhost:5000 上运行。
我还想将我的应用程序作为一项服务每天 24 小时运行,我可以打开和关闭并在后台运行(如果可以的话),而不是作为我必须单独运行的应用程序。
到目前为止,我所做的只是运行 .net 核心 API,但作为来自站点的外部请求(键入 147.135.xxx.xxx / + 端点到 Z8A5DA52ED126447D359E70C057)
这是我的配置 /etc/ngnix/sites/available/default 文件
server {
listen 80;
server_name _;
location / {
proxy_pass http://localhost: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;
}
}
如何配置文件?
创建两个位置,一个用于 api,另一个用于 angular 应用程序。 让 .net 内核中的 api 在端口 8080 上运行,angular 将在端口 5000 上运行。
location /api/ {
proxy_pass http://127.0.0.1:8080; # For Api, add other headers
}
location / {
proxy_pass http://127.0.0.1:5000; # For angular app, add other headers
}
Now by default your angular app will be served on port 80, and if you append the URL by /api, your .net core app will be accessible.
让我们看看...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.