Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

i have .php file wich is loading images to hide their location. Every images are correctly caching through this directive:

location ^~ \.(jpg|jpeg|png|gif|ico|css|js)$ {
            expires max;
            valid_referers server_names blocked mysiteaddresishere;
            if ($invalid_referer) {
               return   403;
            }
}

by the way, valid referers doesn't work, i don't know why too :P.

I've added ^ before ~, someone told that this should look at the longest regex, maybe it do but not with php files.

I have in my vhost something like this:

location ~ \.php$ {
    try_files /a30bc49b5ff24bc50d55ba4306d73470.htm @php;
}

location @php {
    try_files $uri =404;
    include /etc/nginx/fastcgi_params;
    fastcgi_pass 127.0.0.1:9010;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_intercept_errors on;
}

dunno if this is blocking caching on my php image reader, i can't figour out how to add into this expires for images.

I've found this site: en.dklab.ru /lib/HTTP_ImageResizer/ so i've trid like this:

location /imagehi.php {
        fastcgi_cache MYAPP;
        fastcgi_cache_valid 200 304 404 240h;
        fastcgi_cache_key "method=$request_method|ims=$http_if_modified_since|inm=$http_if_none_match|host=$host|uri=$request_uri";
        fastcgi_hide_header "Set-Cookie";
        fastcgi_ignore_headers "Cache-Control" "Expires";

    # or use proxy_* commands if you use Apache, not FastCGI PHP
}

but it still doesn't work. Any ideas what am i missing ?

my whole vhost config file: paste2.org/Fb2dzeKf and nginx.conf file: paste2.org/2cyGNBDK

============ Edit =========

OK, i solved it in php file image.php not in nginx. Solution was in headers i just followed this: http://ernieleseberg.com/php-image-output-and-browser-caching/

share|improve this question
    
location ^~ \.(jpg|jpeg|png|gif|ico|css|js)$ { is perfectly useless. ^~ modificator forbids regexp matching so this location could only matches file with weird name \.(jpg|jpeg|png|gif|ico|css|js)$, but even this is impossible because every location starts with /. –  Alexey Ten Mar 8 at 17:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.