Limiting gzip_static to two directories

I have gzip enabled in Nginx as well as gzip_static. I am trying to
gzip_static to just one or two sections. There are pre-compressed files
inside the directory: media/po_compressor/ along with sub directories of
this such as:

Here is what I have below in nginx. What is the best way to look inside
directory and sub-directories using location entry?

Gzip Static module to compress CSS, JS

location /media/po_compressor/ {
gzip_static on;
expires 365d;
add_header Pragma public;
add_header Cache-Control “public, must-revalidate, proxy-revalidate”;


gzip on;
gzip_buffers 16 8k;
gzip_comp_level 4;
gzip_http_version 1.0;
gzip_min_length 1280;
gzip_types text/plain text/css application/x-javascript
application/xml application/xml+rss text/javascript image/x-icon
gzip_vary on;

Posted at Nginx Forum:,256154,256154#msg-256154

changing location line to:

location ^~ /media/po_compressor/ {

should allow it to look for all files within this directory and
sub-directories, right?

Posted at Nginx Forum:,256154,256155#msg-256155

According to the location
directive documentation, nginx will match one location block only.
nginx will first match the longest prefix location to your request.
If that longest prefix is the one you provided, then regular expression
won’t be checked, as you used the special modifier doing that.
If that longest prefix is another location rule, then nginx will
it, search for regex locations matches, stop at the first one matching
revert back to the longest prefix lcoation found earlier.

So, if you have no longer prefix location matching those URIs, then the
files will be served by it.

B. R.