Considering a nginx server with the following two locations which each serve a webapp, including some static resources and a REST API. Is there a way to cache the common resources, e.g. /proxy/host1/js/vendors.js
and /proxy/host2/js/vendors.js
such that nginx only downloads vendors.js
once from an upstream webapp server and caches it for requests of vendors.js
to different hosts.
location /proxy/host1 {
rewrite /proxy/host1/(.*) /$1 break;
proxy_pass http://host1;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header HOST $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 300;
proxy_connect_timeout 300;
}
location /proxy/host2 {
rewrite /proxy/host2/(.*) /$1 break;
proxy_pass http://host2;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header HOST $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 300;
proxy_connect_timeout 300;
}