I'm using nginx to create reverse proxy for two different applications, one hosted on the server where nginx is hosted at port 8011, and the other hosted on a different server with port number 8015. Using reverse proxy, the first application can be accessed on ROOT:80/
while the second application can be accessed at ROOT:80/blog
.
Now, the static files of both the applications are inside their respective static
folders which are located in two different paths (static path of first application hosted on the same server as nginx: PATH_ONE/static
and static path of the second application: PATH_TWO/static
). Now, the application hosted under ROOT:80/
picks up its static files correctly from the configuration used below. However, I'm not able to figure out how to go about configuring the same for the second application.-
How do I ensure that both applications hosted on different URLs using nginx use their respective static files?
nginx configuration:
upstream test_hosts {
least_conn;
server IP_ADDR_ONE:8011;
server IP_ADDR_TWO:8011;
}
server{
listen 80;
location / {
proxy_pass "http://test_hosts";
}
location /blog {s
rewrite ^/blog(.*) /$1 break;
proxy_pass "http://IP_ADDR_TWO:8015";
}
#browser caching of static assets
location ~* \.(jpg|jpeg|png|gif|ico|css|js|html)$ {
expires 7d;
root /PATH_ONE;
}
}