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

时间:2017-08-17 21:53:45

标签: nginx asp.net-core

我一直在努力使用nginx和supervisor在EC2 ubuntu实例上运行一些asp.net核心webapps。我成功地一次运行一个应用程序,只需在我的nginx设置中交换我的端口并重新加载我可以在运行5000和5001的运行.netcore应用程序之间切换。我似乎无法找出nginx设置来使它们两者在路径上工作,即:hostname / app1,hostname / app2。

这是我的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;
    }
}

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

1 个答案:

答案 0 :(得分:4)

看起来解决方案是在位置和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;
    }
}