proxy - proxying relative urls with nginx -
my question similar nginx relative url absolute rewrite rule? - added twist.
i have nginx acting proxy server, proxies multiple apps, similar (simplified) config:
server { listen 80; server_name example.com; location /app1 { proxy_pass http://app1.com; } location /app2 { proxy_pass http://app2.com; } } this works fine, in other question, these applications (app1 , app2) use relative urls such /css/foo.css, or /js/bar.js. it's big problem ask applications change /app1/css/foo.css.
is possible nginx intelligently figure out application should handle request? ftr, users accessing these applications this:
http://example.com/app1/fooaction or http://example.com/app2/baraction.
if matters, applications java/tomcat based apps.
tia!
based on updated comments; if upstream backend sends referer header, this:
location ~* ^/(css|js)/.+\.(css|js)$ { #checking if referer app1 if ($http_referer ~ "^.*/app1"){ return 417; } #checking if referer app2 if ($http_referer ~ "^.*/app2"){ return 418; } } error_page 417 /app1$request_uri; error_page 418 /app2$request_uri; location /app1 { proxy_pass http://app1.com; } location /app2 { proxy_pass http://app2.com; } for example, if backend on app2.com, requests test.css this:
curl 'http://example.com/css/test.css' -h 'referer: http://app2.com/app2/some/api' the request land here:
/app2/css/test.css
Comments
Post a Comment