title: Rewriting paths in CSS & JS via nginx's sub_filter
body: <p>I'm having a problem with nginx's <code>sub_filter</code> rewrite rules not working with CSS files. I'm serving content on a path (<code>/site</code>) and need all URLs in JS &amp; CSS to be prefixed correctly.</p>
  
  <p>I've specified the mime type when linking in the CSS. From the template:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;link href="/static/css/site.css" type="text/css" rel="stylesheet" /&gt;
  </code></pre>
  
  <p>nginx has sub filters enabled and I've explicitly specified to include <code>text/css</code>:</p>
  
  <pre><code>location /site {
      access_log /opt/logs/test/nginx-access-site.log combined if=$loggable;
      error_log  /opt/logs/test/nginx-errors-site.log error;
  
      rewrite ^(/site)$ $1/;
      rewrite ^/site(.+) $1 break;
  
      sub_filter "test.domain.tld" "test.domain.tld/site";
      sub_filter "'/" "'/site/";
      sub_filter '"/' '"/site/';
      sub_filter "http:" "https:";
      sub_filter_types text/html text/css text/javascript;
      sub_filter_once off;
  
      include proxy_params;
      proxy_pass http://site_test$1$is_args$args;
      proxy_redirect http://test.domain.tld/ https://test.domain.tld/site/;
  }
  </code></pre>
  
  <p>The reference to the CSS file is rewritten correctly. From the HTML output:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;link href="/site/static/css/site.css" type="text/css" rel="stylesheet" /&gt;
  </code></pre>
  
  <p>The issue is it's not rewriting within the CSS file, so image paths are incorrect:</p>
  
  <pre class="lang-css prettyprint-override"><code>.sortable th .asc {
    background-image: url("/static/img/up_arrow.gif");
  }
  </code></pre>
  
  <p>I've tried being overly permissive without any difference:</p>
  
  <pre><code>    sub_filter_types *;
  </code></pre>
  
  <p>Have I misunderstood the use of <code>sub_filter</code>? I assumed that because the CSS was being served directly by nginx it would also be rewritten.</p>