Hello Rahul & crew,
this is not a WP-Nginx related topic, but since you are so highly knowledgeable in the Nginx area, I was hoping you could shed some light on an issue I'm having.
I have been testing the following Nginx FastCGI cache config for Magento. 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. Probably here:
## Forward paths like /js/index.php/x.js to relevant handler (correct/needed?)
location ~ .php/ { rewrite ^(.*.php)/ $1 last; }
or here:
## Catch 404s that try_files miss (correct/needed?)
if (!-e $request_filename) { rewrite / /index.php last; }
Here's my virtual host config (non-relevant parts omitted):
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 {
## Catch 404s that try_files miss (correct/needed?)
if (!-e $request_filename) { rewrite / /index.php last; }
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 APP;
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 {
## Catch 404s that try_files miss (correct/needed?)
if (!-e $request_filename) { rewrite / /index.php last; }
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=/"; }
}
Any help is more than welcome!
Thanks and keep up the great work!