Nginx's sub_filter does not replace paths in CSS and JS

Francis Daly francis at daoine.org
Thu Feb 6 19:54:11 UTC 2020


On Wed, Feb 05, 2020 at 07:04:09AM -0500, !QVAS! wrote:

Hi there,

> location /new {
>         proxy_pass http://172.22.3.15/;
>     }

>      server {
>             listen       80;
>             server_name  172.22.3.15;
> 
>             location / {
>                 proxy_pass http://172.22.3.16:8000;
>                 proxy_redirect / /new;
>                 sub_filter '"/' '"/new/';
>                 sub_filter "'/" "'/new/";
>                 sub_filter_types *;
>                 sub_filter_once off;
>                 sub_filter_last_modified on;
>                 proxy_set_header Accept-Encoding "";
>             }
>         }
> But the problem is that in the CSS and JS files themselves, the paths are
> not changed. 

When I use your config, it seems to work for me.

Can you show one request and the matching incorrect response?

Small is good; something like

  curl -v http://examplesite.com/new/a.js

should work -- the matching file a.js in the 172.22.3.16:8000 document
root should have suitable content.

  curl -v http://172.22.3.15/a.js
  curl -v http://172.22.3.16:8000/a.js

might also be useful, to compare.

	f
-- 
Francis Daly        francis at daoine.org


More information about the nginx mailing list