nginx - response based on the requested header nginx - response based on the requested header nginx nginx

nginx - response based on the requested header


map lets you define a variable's value based on another variable. map should be declared at http level (i.e. outside of server):

map $http_x_header $file_suffix {  default "2";  OK      "1";};

Then the following location should do the trick using your new variable $file_suffix

location ~ ^(/files_dir/.+)\.js$ {  root html;  try_files $1$file_suffix.js =404;}


You could do this with nginx very easily. This is example:

location /files_dir/ {    set $file = file2.js;    if ( $http_x_header = OK ) {        set $file = file1.js;    }    rewrite ^(/files_dir/.*)/file.js$ $1/$file last;}

You could read about HTTP variables in NGINX here , and about nginx rewrite module here