We recently migrated to nginx and we need to transfer as well our htaccess config the like below from a certain directory/path(www.domain.com/images/test.jpg) in which that image file contains a php code that we want to run.
AddHandler application/x-httpd-ea-php56 .jpg .png .gif
Did some research and found examples below, but since I am not really that familiar with how to configure nginx, I am not sure why it isn't working.
first:
location ~ \.(php|jpg)$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
second:
location ~ .*\.php$ {
root /var/www/html/www.domain.com;
if (!-f $request_filename) {
rewrite ^/(.*)$ /index.php?q=$1;
break;
}
include fastcgi_params;
#root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_intercept_errors off;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/www.domain.com$fastcgi_script$
}
I hope some can help me.
UPDATE 08/09/2019 -- ANSWER
location ~ ^/pathname/images/(.*)\.(jpg|png|gif)$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
Can you try this code:
location ~* \.(jpg|jpeg|gif|png|bmp)$ {
try_files $uri $uri/ /index.php$is_args$args;
add_header Cache-Control public;
add_header Cache-Control must-revalidate;
expires 7d;
}
You might need to modify /index.php?$is_args$args
part on the try_files line so that you get the correct parameters for your script, as your initial question didn't show clearly what the parameters are you want.
Credits goes to nginx serve image via php script
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With