nginx - nginx上的asp.net核心多个应用程序

标签 nginx asp.net-core

我一直在努力使用 nginx 和主管在 EC2 ubuntu 实例上运行几个 asp.net 核心 web 应用程序。我成功地一次运行一个应用程序,只需在我的 nginx 设置中交换我的端口并重新加载,我就可以在 5000 和 5001 上运行的正在运行的 .netcore 应用程序之间进行交换。我似乎无法弄清楚 nginx 设置使它们同时存在在路径上工作,即:主机名/应用程序1,主机名/应用程序2。

这是我的 Nginx 配置。谁能指出我做错了什么?我的主管正在运行这两个应用程序,我可以通过查看日志并更改默认位置“/”中的端口来验证这一点。

server {
    listen 80 default_server;
    listen [::]:80 default_server;

#    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;
#    }


    location /app1 {
            rewrite ^/app1(.*) /$1 break;
            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;
    }

    location /app2{
            rewrite ^/app2(.*) /$1 break;
            proxy_pass http://localhost:5001;
            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;
    }
}

我没有简单的默认路线,因为我还没有任何东西可以放在那里。

最佳答案

看起来解决方案是在位置和代理通行证上添加斜杠

server {
    listen 80 default_server;
    listen [::]:80 default_server;

#    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;
#    }


    location /app1/ {
            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;
    }

    location /app2/ {
            proxy_pass http://localhost:5001/;
            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;
    }
}

关于nginx - nginx上的asp.net核心多个应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45745503/

相关文章:

nginx - 从 nginx 提供 golang 脚本

nginx - 重用 nginx.conf 中域的配置语句

sqlite - 在没有任何仪表板的情况下使用 HangFire

c# - ActionResult 扩展不适用于 Page() ActionResult 方法

wordpress - NGINX 代理到 wordpress 网站

javascript - MySql 命令可以从终端运行,但不能从 Node js 运行

asp.net-core - ODP.NET Core - 脚手架数据库上下文

asp.net-core - 如何从 web.config、API 调用返回 index.html 复制 .​​net 核心启动中的重写规则

xml - 返回 "application/xml"而不是 "text/plain"ASP.NET Core Web API

python - 由 zeromq 触发的 nginx 背后的 Websockets?