Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net core multiple apps on nginx

I have been working to get a couple asp.net core webapps running on EC2 ubuntu instance using nginx and supervisor. I am successful in running one app at a time and by simply swapping my port in my nginx setting and reloading I can swap between the running .netcore apps running on 5000 and 5001. I cannot seem to figure out the nginx settings to make them both work at a path, ie: hostname/app1, hostname/app2.

Here is my Nginx Config. Could anyone point to something I have done wrong? My supervisor is running both apps I can verify that by looking at the logs and also changing the port in the default location "/".

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

I do not have a default route simple because I don't have anything to put there yet.

like image 395
JoAMoS Avatar asked Aug 17 '17 21:08

JoAMoS


1 Answers

Looks like the solution was trailing slashes on the location and 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;
    }
}
like image 129
JoAMoS Avatar answered Sep 30 '22 12:09

JoAMoS