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.

This problem is driving me crazy. I tried fixing it for at least 30mins now

if i comment out my try_files everything works correctly except my cache files are not being served (i checked via log files)

if i have the following urls

/
/name
/name/

They should match up to the files below.

/var/www/domain/cache/index.html
/var/www/domain/cache/name/index.html
/var/www/domain/cache/name/index.html

How do i use try_files to check them and if the html cache doesnt exist proceed to the rest of the location block. Here is the block in quest

location ~ /$ {
    #try files here
    root /var/www/domain/;
    include /etc/nginx/fastcgi_params;
    fastcgi_pass unix:/var/run/php-fastcgi/php-fastcgi.socket;
    fastcgi_param SCRIPT_FILENAME $document_root/index.php;
}
share|improve this question
    
Do you send all your requests to fastcgi/php? –  Marcelo Bittencourt Nov 9 '11 at 17:24
    
@MarceloBittencourt yes but that generates the cache file and serves the html result. I want to try files so i can directly use cache when they exist. –  acidzombie24 Nov 10 '11 at 1:33
add comment

1 Answer 1

up vote 1 down vote accepted

Try something like that:

server {
     ...
     location @whatever {
        root /var/www/domain/;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/var/run/php-fastcgi/php-fastcgi.socket;
        fastcgi_param SCRIPT_FILENAME $document_root/index.php;
        }
     location ~ /$ {
        root /var/www/domain/cache/;
        try_files $uri $uri/ @whatever;
        }
}

Let me know if it worked...

share|improve this answer
    
I dont see where i specify the cache location but i tried ` location ~ /$ { root /path/cache; try_files $uri @whatever; }` and putting the full location instead of using document_root. I looked at the access log an it said i tried to serve $document_root/page instead of $document_root/index.php –  acidzombie24 Nov 10 '11 at 2:10
    
strange, with this incorrect configuration i can it doesnt seem to use the cache files and it reports the access of @whatever as /usr/local/nginx/html –  acidzombie24 Nov 10 '11 at 2:17
    
the cache location normally is your document root... when you don't find the file you always call index.php? without adding any parameters? Can you add the access and error log messages after a request? –  Marcelo Bittencourt Nov 10 '11 at 2:17
    
Sorry. i thought that you had the root value in the server context (will edit this response...) –  Marcelo Bittencourt Nov 10 '11 at 2:20
    
With your edit i still dont know where to put the cache path I tried it with root being at the top but got the problem with it not checking the cache location I played around more and i still cant figure this out. So heres the thing, i have a cache location /path/to/app/cache/folder_aka_url/index.html; which should fall back to /path/to/app/index.php;. Then regular files at /path/to/app/$uri and finally php files that isnt index.php also at /path/to/app/$uri (uri can be subfolders). I dont have root just because i have no idea how to say look-here-instead-of-root in a specific location –  acidzombie24 Nov 10 '11 at 2:27
show 3 more comments

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.