B
B
barkalov2014-06-24 10:58:16
Nginx
barkalov, 2014-06-24 10:58:16

How to use nginx to give a file whose name is generated by a script?

I do CNC . I would like nginx to do rewrite not based on the regular expression from the config, but based on the result of the script.
Like something like this:

location /products {
    proxy_pass localhost:1234/getProductFileName.js
    rewrite ^(.*)$ proxy_pass_result
}

For example:
  1. Request for /products/primer .
  2. Nginx goes to localhost:1234/getProductFileName.js?primer .
  3. The script responds to nginx (in body or header) with the line: /products/grunt.html
  4. Nginx does a rewrite and returns /products/grunt.html (at the original address in the browser /products/grunt )

Of course, I can give the script the file itself (or empty html with the ssi include directive). But firstly, I want unification (so that files are given only to nginx, without the zoo), if possible. Secondly, I want standard nginx 404 errors if the file does not exist.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mandor, 2014-06-24
@barkalov

Header "X-Accel-Redirect".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question