A
A
Ad4ptec2015-05-20 15:53:24
Nginx
Ad4ptec, 2015-05-20 15:53:24

How to set exceptions in nginx rewrite regular expression?

All .js files are redirected to a php script for processing and subsequent output of the formatted .js file. The challenge was to keep all .js paths the same. The code below is failing.

set $domain $host;
  rewrite "^/gzip/(.*)$" /gzip.php?file=http://$domain/$1 last;
  location ~* \.js$ {
    rewrite_log on;
    rewrite "^/(.*)$" /gzip/$1 last;
  }

location .js causes a circular redirect after it redirects to the /gzip/ directive, i.e. in the redirect logs it writes:
/gzip/file.js
/gzip/gzip/file.js
/gzip/gzip/gzip/file.js и т.д.

Is it possible to add exceptions to /gizp/ and the gzip.php file as a regular expression for this redirect rewrite "^/(.*)$" /gzip/$1 last; ? Or location.js?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Antony Ryabov, 2015-05-20
@tonymadbrain

You have some kind of complex scheme, but why not just do it like this?:

location ~* \.js$ {
    rewrite_log on;
    rewrite "^/gzip/(.*)$" /gzip.php?file=http://$domain/$1 last;
  }

well, for /gzip the same location.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question