I have been testing the following FastCGI cache config (non-relevant parts ommited) on a Magento store and everything seems to be working just fine. The only problem is that, no matter what rewrite rule I use, Nginx is not parsing the index.php file (always prompting me to download it).
I'm definitely missing something. Any help/suggestion would be more than welcome!
==
location /index {
try_files $uri @fcgi_nocache;
}
location /checkout {
try_files $uri @fcgi_nocache;
}
location / {
try_files $uri @fcgi_cache;
if ($cookie_frontend) { return 413; }
if ($cookie_CUSTOMER_AUTH) { return 413; }
if ($request_method = POST ) { return 413; }
error_page 413 = @fcgi_nocache;
}
## Forward paths like /js/index.php/x.js to relevant handler (correct/needed?)
location ~ .php/ { rewrite ^(.*.php)/ $1 last; }
location @fcgi_cache {
if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss (correct/needed?)
fastcgi_pass unix:/var/spool/phpfpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_param SCRIPT_NAME /index.php;
fastcgi_cache MAGE;
fastcgi_cache_key "$scheme$request_method$host$request_uri$http_if_modified_since$http_if_none_match";
fastcgi_cache_valid 200 301 302 304 1h;
fastcgi_hide_header "Set-Cookie";
if ($http_cookie !~ "X-Store=1" ) { add_header Set-Cookie "X-Store=1; path=/"; }
fastcgi_ignore_headers "Cache-Control" "Expires" "Set-Cookie";
fastcgi_cache_min_uses 1;
fastcgi_cache_valid 30m;
fastcgi_cache_use_stale updating error timeout invalid_header http_500;
fastcgi_cache_bypass $cookie_EXTERNAL_NO_CACHE $cookie_CUSTOMER_AUTH;
fastcgi_no_cache $cookie_EXTERNAL_NO_CACHE $cookie_CUSTOMER_AUTH;
add_header X-Nginx-Cache $upstream_cache_status;
}
location @fcgi_nocache {
if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss (correct/needed?)
fastcgi_pass unix:/var/spool/phpfpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_param SCRIPT_NAME /index.php;
if ($http_cookie !~ "X-Store=1" ) { add_header Set-Cookie "X-Store=1; path=/"; }
}
==