ASP.NET Core在Nginx上多应用程序部署

7
我一直在努力通过使用nginx和supervisor在EC2 ubuntu实例上运行几个asp.net core web应用程序。我已成功地一次运行一个应用程序,通过简单地在我的nginx设置中交换端口并重新加载,我可以在5000和5001上运行的.netcore应用程序之间进行切换。但我似乎无法弄清楚nginx设置,使它们都在路径上工作,即:主机名/应用程序1,主机名/应用程序2。
这是我的Nginx配置。有人能指出我做错了什么吗? 我的supervisor正在运行两个应用程序,我可以通过查看日志并更改默认位置“/”中的端口来验证。
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;
    }
}

我没有默认路由,因为我还没有东西放在那里。

1个回答

8

看起来问题在于location和proxypass后面的斜杠

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

你的解决方案不起作用,因为它只响应第一个请求,而 .net core 应用程序无法解析路由,例如 localhost/app1..... - ADIMO

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接