Search code examples
nginxpathabsoluteproxypass

Nginx proxy_pass location absolute paths


I had a proxied page: http://destsrv:8089/index.html It contains link to absolute path like: href="/static/bootstrap/css/bootstrap.min.css"

And nginx is configured like:

 location /admin/ {
              proxy_pass http://destsrv:8089/;
        }

Although when accessing the http://myproxy/admin/index.html it is trying to get .css from: http://myproxy/static/bootstrap/css/bootstrap.min.css

But expected is: http://myproxy/admin/static/bootstrap/css/bootstrap.min.css

How to do it?


Solution

  • Try this

    location /admin/ {
       proxy_pass http://destsrv:8089/;
       sub_filter_once off;
       sub_filter "http://destsrv:8089/" "$scheme://$host/admin";
       sub_filter 'href="/' 'href="/admin/';
       sub_filter "href='/" "href='/admin/";
    }
    

    You basically want to fix the urls using filters