0

i have setup nginx as reverse proxy for different web apps running on apache server:

/var/www/app_abc
|-static
|    |-app.js
|    |-app.css
|-index.html

/var/www/app_xyz
|-static
|     |-app.js
|     |-app.css
|-index.html

the app_abc runs on apache virtual host port 8081 the app_xyz runs on apache virtual host port 8082

they work fine in apache if access them :

curl http://localhost:8081
curl http://localhost:8082

now i only have one domain : real-domain.com i can not create subdomain like , abc.domain.com or xyz.domain.com

i have the nginx config like this:

by default goes to app_abc when request 'http://www.real-domain.com':

location / {
    proxy_pass http://localhost:8081
}

if request http://www.real-domain.com/xyz, goes to app_xyz

location ~ /xyz(.*) {
 rewrite ^/xyz/?(.*) /$1 break;
 proxy_pass http://localhost:8082;
}

for static files

location ~ ^/static {
   try_files $uri $uri/ /var/www/app_abc/$uri /var/www/app_xyz/$uri;
}

the only problem here is that the those requests:

static/app.js
static/app.cs

for "http://www.real-domain.com/xyz" will return 404

but works for "http://www.real-domain.com/"

my question is :

how to serve static files for different apps where static files in different apps have same relative paths ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.