I have a server hosting multiple .NET Core applications on different ports, with nginx reverse proxy setup to redirect users to the correct application via URL.
The current setup is as followed:
Upstream:
upstream app1 {
server 127.0.0.1:44305;
}
upstream app2 {
server 127.0.0.1:44306;
}
Location:
location /app1/ {
rewrite ^/app1/?(.*)$ /$1 break;
proxy_pass http://app1;
}
location /app2/ {
rewrite ^/app2/?(.*)$ /$1 break;
proxy_pass http://app2;
}
I can access the application via https://mywebsite.com/app1 and https://mywebsite.com/app2, however the 2 sites cannot load their respective static files (under the wwwroot folder). When I check the developer console, the error was that the static file being load is https://mywebsite.com/static/image.png instead of https://mywebsite.com/app1/static/image.png, which was the cause of the 404 error when loading the static files.
I have tried adding a location block to specify the static folder:
location ~* /app1/.(css|js|lib|ico)$ {
alias /var/www/app1/wwwroot/;
}
But it still doesn't work.
Update from this answer, I added this block:
location /static/ {
proxy_pass http://app1/static/;
}
Now that the static file is redirected from https://mywebsite.com/static to https://mywebsite.com/app1/static/. However, both apps are redirecting the app1 static folder. What can I do to distinguish between the static requests from each application?