nginx - questions about $args on try_files inside location with regex -


(sorry bad english)

i have url this:

http://www.domain.com/resize.php?pic=images/elements/imagename.jpg&type=300crop

that php checks if image exists , serves, if not, creates image on disk size specified in type parameter , returns it.

what wanted check if image exists on disk @ size, nginx, run resize.php when necessary create image.

i tried this, think location directive doesn't operate on query parameters ($args) using regex, loncation not match sample url :(

any please?

i need rewrite parameters ($args) , use them in try_files directive... possible?

location ~ "^/resize\.php\?pic=images/(elements|gallery)/(.*)\.jpg&type=([0-9]{1,3}[a-z]{0,4})$)" {    try_files /images/$1/$2.jpg /imagenes/elements/thumbs/$3_$2.jpg @phpresize; }  location @phpresize {   try_files $uri =404;   proxy_set_header host $host;   proxy_set_header x-real-ip $remote_addr;   proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;   proxy_buffering on;   proxy_pass http://www.localhost.com:8080; } 

you cannot match query string in location (e.g., see here , here). way process requests differently depending on query string contents use if , conditional rewrites.

however, if ok handle requests /resize.php not have expected query parameters using @phpresize location config, can try this:

map $arg_pic $image_dir {     # subdirectory name should not exist.     default invalid;      ~^images/(?p<img_dir>elements|gallery)/.*\.jpg$      $img_dir; }  map $arg_pic $image_name {     # ".*" match here might insecure - using "[-a-z0-9_]+"     # better if matches image names;     # choose regexp appropriate situation.     ~^images/(elements|gallery)/(?p<img_name>.*)\.jpg$   $img_name; }  map $arg_type $image_type {     ~^(?p<img_type>[0-9]{1,3}[a-z]{0,4})$    $img_type; }  location ~ "^/resize.php$" {     try_files /images/${image_dir}/${image_name}.jpg /imagenes/elements/thumbs/${image_type}_${image_name}.jpg @phpresize; }  location @phpresize {     # no changes config here.     try_files $uri =404;     proxy_set_header host $host;     proxy_set_header x-real-ip $remote_addr;     proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;     proxy_buffering on;     proxy_pass http://www.localhost.com:8080; } 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -