Nginx FastCGI Cache $upstream_cache_status; Not Showing - caching

So I have been trying to implement the fastcgi cache on nginx. To test whether the cache is working, I added the header to display the cache status, HIT, MISS, etc using the following line:
add_header X-Cache $upstream_cache_status;
Problem is the header doesn't show up at all. When I hard code a value for the X-Cache header, it shows up though.
My nginx version information:
nginx version: nginx/1.4.6 (Ubuntu) built by gcc 4.8.4 (Ubuntu
4.8.4-2ubuntu1~14.04) TLS SNI support enabled configure arguments: --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_spdy_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module
My site-enabled config:
# You may add here your
# server {
# ...
# }
# statements for each of your virtual hosts to this file
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##
#move next 4 lines to /etc/nginx/nginx.conf if you want to use fastcgi_cache across many sites
fastcgi_cache_path /var/run/nginx-cache levels=1:2 keys_zone=WORDPRESS:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_cache_use_stale error timeout invalid_header updating http_500;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/;
index index.html index.htm index.php;
server_name thinkingtypes.com;
include hhvm.conf;
set $skip_cache 0;
# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
set $skip_cache 1;
}
if ($query_string != "") {
set $skip_cache 1;
}
# Don't cache uris containing the following segments
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
set $skip_cache 1;
}
# Don't use the cache for logged in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
set $skip_cache 1;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
add_header X-Cache $upstream_cache_status;
include fastcgi_params;
fastcgi_pass unix:/var/run/hhvm/hhvm.sock;
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache WORDPRESS;
fastcgi_cache_valid 60m;
}
location ~ /purge(/.*) {
#fastcgi_cache_purge WORDPRESS "$scheme$request_method$host$1";
}
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
access_log off; log_not_found off; expires max;
}
location = /robots.txt { access_log off; log_not_found off; }
location ~ /\. { deny all; access_log off; log_not_found off; }
}

Okay solved the issue myself, HHVM created another file hhvm.conf which handles php files separately though port or sock. I just needed to place the add header there, within that block for it to show up. Anywhere else, the upstream_cache variable was empty as it was not being set, due to the cache not being used.

You can also use nginx module
more_set_headers
by installing this https://github.com/openresty/headers-more-nginx-module#name nginx module.
then add this config to set your nginx header.
more_set_headers 'X-Cached: $upstream_cache_status';

Related

Nginx fastcgi param doesn't get to CodeIgniter

I have set a fastcgi_param ENVIRONMENT at nginx virtual host file, but I can't access that value inside CodeIgniter:
var_dump(defined('ENVIRONMENT')); //outputs false
Full nginx virtual host file:
server {
listen 80;
# Hostnames alias
server_name webapp1;
root /home/edson/repositorios/webapp1;
index index.php index.html;
location /bec/admin {
try_files $uri $uri/ /bec/admin/index.php$is_args$args;
}
location /bec {
try_files $uri $uri/ /bec/index.php$is_args$args;
}
#
# Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
include /etc/nginx/php.conf;
fastcgi_param ENVIRONMENT development;
}
# Nginx Cache Control for Static Files (Browser Cache Control Directives)
location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml|xls|xlsx|doc|docx|csv|txt)$ {
access_log off;
log_not_found off;
expires max;
}
#
# deny access to .htaccess files, and hidden files, which starts with dot (.), if Apache's document root
# concurs with nginx's one
#
location ~ /\. {
access_log off;
log_not_found off;
deny all;
}
}
Am I doing something wrong?
That is a environment variable, so it can be accessed through getenv:
Gets the value of an environment variable
Example
getenv('ENVIRONMENT');

Cache Zend Framework homepage on nginx

I have zend framework 1.12 based site working with nginx
I installed wnmp on windows 7 professional to test Windows, nginx, mariadb, php7
I want to cache home page which is localhost or localhost/
which internally calls index.php using index.php
similarly urls http://localhost/conference/sessions/date/2015-04/12/page/1 conference - controller sessions - action request params date, and page with respective values
I want to cache home page but I have looked but nothing specific is available
Here is my nginx.conf that works without caching
here is what I have in my nginx.conf
worker_processes 1;
error_log logs/error.log;
pid logs/nginx.pid;
events {
# Max value 16384
worker_connections 8192;
# Accept multiple connections
multi_accept on;
}
# Settings that affect all server blocks
http {
include php_processes.conf;
include mime.types;
default_type application/octet-stream;
access_log logs/access.log;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
sendfile on;
keepalive_timeout 65;
ssl_session_timeout 10m;
ssl_protocols TLSv1.2 TLSv1.1 TLSv1 SSLv3;
ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AES:RSA+3DES:!ADH:!AECDH:!MD5:!DSS;
ssl_prefer_server_ciphers on;
gzip on;
# http server
# Begin HTTP Server
server {
listen 80; # IPv4
server_name localhost;
## Parametrization using hostname of access and log filenames.
access_log logs/localhost_access.log;
error_log logs/localhost_error.log;
## Root and index files.
root html;
index index.php index.html index.htm;
## If no favicon exists return a 204 (no content error).
location = /favicon.ico {
try_files $uri =204;
log_not_found off;
access_log off;
}
## Don't log robots.txt requests.
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
## Try the requested URI as files before handling it to PHP.
location / {
## Regular PHP processing.
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass php_processes;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
## Static files
location ~* \.(?:css|gif|htc|ico|js|jpe?g|png|swf)$ {
expires max;
log_not_found off;
## No need to bleed constant updates. Send the all shebang in one
## fell swoop.
tcp_nodelay off;
## Set the OS file cache.
open_file_cache max=1000 inactive=120s;
open_file_cache_valid 45s;
open_file_cache_min_uses 2;
open_file_cache_errors off;
}
## Keep a tab on the 'big' static files.
location ~* ^.+\.(?:ogg|pdf|pptx?)$ {
expires 30d;
## No need to bleed constant updates. Send the all shebang in one
## fell swoop.
tcp_nodelay off;
}
try_files $uri $uri/ #missing;
} # / location
location #missing {
rewrite (.*) /index.php;
}
}
Please help.
Added Under http
note - add two underscores (__) if you cookie starts with and underscore (_)
fastcgi_cache_path /home/k47/cache/nginx levels=1:2 keys_zone=MYHOMEPAGE:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_method$query_string$request_uri$cookie_one$cookie_two$cookie__ga$cookie__gat";
fastcgi_cache_use_stale error timeout invalid_header http_500;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
fastcgi_cache_valid 200 302 1m;
Under server set a flag/variable which can be used to determine if we need caching or not
I have used other urls to cache and not cache with similar regex
set $no_cache 1;
if ($request_uri ~* "^/$")
{
set $no_cache 0;
}
then finally under location {} I start with
fastcgi_cache_bypass $no_cache;
fastcgi_no_cache $no_cache;
fastcgi_cache MYHOMEPAGE;
fastcgi_cache_valid 200 1m;
add_header X-Proxy-Cache $upstream_cache_status;
add_header cache-control 'public, max-age=500';

Magento Nginx sub-page rewrites

I am in the process of switching from Apache to Nginx for Magento but cannot seem to get it set up and working correctly. I have installed everything on a test server and the magento install went fine and I can access both the home page and the admin panel correctly but if I navigate to any sub-page from the frontend, the URL loses the "index.php" and gives me a 500 internal server error. For example if I try /magento/contacts/ I get a 500 error but if I add /magento/index.php/contacts/ it loads.
I have tried countless different nginx configurations but none have worked. I have trawled the posts on here relating to the same issue but no joy. My last hope is to post my config file on here and hope that someone can help!
I followed this: https://gist.github.com/tegansnyder/96d1be1dd65852d3e576 tutorial to the letter and everything works great except the problem above.
Any suggestions would be GREATLY appreciated! I'm tearing my hair out here! Thanks in advance!
I have two config files:
FIRST CONFIG FILE
server {
server_name 192.121.166.136;
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log info;
# 504 is a PHP timeout and must be static
# 502 is momentary during a PHP restart and should be treated like maintenance
# other 50x errors are handled by Magento
error_page 502 504 /var/www/magento/504.html;
listen 80;
#listen 443 ssl;
# if you are using a load balancer uncomment these lines
# header from the hardware load balancers
#real_ip_header X-Forwarded-For;
# trust this header from anything inside the subnet
#set_real_ip_from X.X.X.1/24;
# the header is a comma-separated list; the left-most IP is the end user
#real_ip_recursive on;
# ensure zero calls are written to disk
client_max_body_size 16m;
client_body_buffer_size 2m;
client_header_buffer_size 16k;
large_client_header_buffers 8 8k;
root /var/www/;
index index.php;
fastcgi_read_timeout 90s;
fastcgi_send_timeout 60s;
# ensure zero calls are written to disk
fastcgi_buffers 512 16k;
fastcgi_buffer_size 512k;
fastcgi_busy_buffers_size 512k;
# remove the cache-busting timestamp
location ~* (.+)\.(\d+)\.(js|css|png|jpg|jpeg|gif)$ {
try_files $uri $1.$3;
access_log off;
log_not_found off;
expires 21d;
add_header Cache-Control "public";
}
# do not log static files; regexp should capture alternate cache-busting timestamps
location ~* \.(jpg|jpeg|gif|css|png|js|ico|txt|swf|xml|svg|svgz|mp4|ogg|ogv)(\?[0-9]+)?$ {
access_log off;
log_not_found off;
expires 21d;
add_header Cache-Control "public";
}
# Server
include main.conf;
include security.conf;
}
SECOND CONFIG FILE
rewrite_log on;
location / {
index index.php;
try_files $uri $uri/ #handler;
}
location #handler {
rewrite / /index.php;
}
## force www in the URL
if ($host !~* ^www\.) {
#rewrite / $scheme://www.$host$request_uri permanent;
}
## Forward paths like /js/index.php/x.js to relevant handler
location ~ \.php/ {
rewrite ^(.*\.php)/ $1 last;
}
location /media/catalog/ {
expires 1y;
log_not_found off;
access_log off;
}
location /skin/ {
expires 1y;
}
location /js/ {
access_log off;
}
location ~ \.php$ { ## Execute PHP scripts
if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss
expires off; ## Do not cache dynamic content
# for this tutorial we are going to use a unix socket
# but if HHVM was running on another host we could forego unix socket
# in favor of an IP address and port number as follows:
#fastcgi_pass 127.0.0.1:8080;
fastcgi_pass unix:/var/run/hhvm/sock;
fastcgi_index index.php;
#fastcgi_param HTTPS $fastcgi_https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# if you need to explictly specify a store code for Magento do it here
# this is useful if you are running multiple stores with different hostnames
#fastcgi_param MAGE_RUN_CODE default;
#fastcgi_param MAGE_RUN_TYPE store;
include fastcgi_params; ## See /etc/nginx/fastcgi_params
fastcgi_keep_conn on; #hhvm param
}
The problem was that my store was in /var/www/magento. Moved the files to just /var/www and all is good :) Thank for the help guys.
Please have a complete reading of this document: http://info.magento.com/rs/magentocommerce/images/MagentoECG-PoweringMagentowithNgnixandPHP-FPM.pdf where you can find a basic NGINX configuration specifically for Magento:
server {
listen 80 default;
# like ServerName in Apache
server_name magento.lan www.magento.lan;
# document root, path to directory with files
root /var/www/magento;
index index.html index.php;
# we don’t want users to see files in directories
autoindex off;
location ~ (^/(app/\|includes/\|lib/\|/pkginfo/\|var/\|report/config.
xml)\|/\.svn/\|/\.git/\|/.hta.+) {
#ensure sensitive files are not accessible
deny all;
}
location / {
# make index.php handle requests for /
try_files $uri $uri/ /index.php?$args;
# do not log access to static files
access_log off;
# cache static files aggressively
expires max;
}
location \~\* \.(jpeg\|jpg\|gif\|png\|css\|js\|ico\|swf)$ {
# look for static files in root directory
# and ask backend if not successful
try_files $uri $uri/ #proxy;
expires max;
access_log off;
}
location #proxy {
# proxy everything from this location to backend
fastcgi_pass fpm_backend;
}
location \~\.php$ {
# if reference to php executable is invalid return 404
try_files $uri =404;
# no need to cache php executable files
expires off;
fastcgi_read_timeout 600;
# proxy all requests for dynamic content to
fastcgi_pass fpm_backend;
# backend configured in upstream.conf
fastcgi_keep_conn on; # use persistent connects to backend
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root${fastcgi_script_name};
# Store code is defined in
# administration > Configuration > Manage Stores
fastcgi_param MAGE_RUN_CODE default;
fastcgi_param MAGE_RUN_TYPE store;
}
}

Joomla with Nginx Rewrite SEF url

I am using Ubuntu 12.04 with NGINX and PHP5-FPM. I've just migrated my Joomla website from Apache to NGINX. But i think rewrite rules are not working well.
All of the SEF links rewrite to the homepage, but in the url bar link seems right.
Example if i click example.com/a/b.html it looks like go to the link in the url bar but homapage is loading.
Thanks for your help.
/etc/nginx/sites-available/example.com file
server {
listen 80;
server_name example.com;
#server_name_in_redirect off;
#access_log /var/log/nginx/localhost.access_log main;
#error_log /var/log/nginx/localhost.error_log info;
root /var/www/example.com/public_html/;
index index.php index.html index.htm default.html default.htm;
# Support Clean (aka Search Engine Friendly) URLs
location / {
try_files $uri $uri/ /index.php?q=$request_uri;
}
# deny running scripts inside writable directories
location ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|asp|sh|cgi)$ {
return 403;
error_page 403 /403_error.html;
}
location ~ \.php$ {
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
#fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# caching of files
location ~* \.(ico|pdf|flv)$ {
expires 1y;
}
location ~* \.(js|css|png|jpg|jpeg|gif|swf|xml|txt)$ {
expires 14d;
}
}
nginx.conf
user www-data;
worker_processes 8;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 30;
types_hash_max_size 2048;
server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
gzip_vary on;
# gzip_proxied any;
gzip_comp_level 6;
# gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##
#include /etc/nginx/naxsi_core.rules;
##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##
#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;
## Block spammers and other unwanted visitors ##
include /etc/nginx/blockips.conf;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
Yes - this reply is over 3 years old, but, unfortunately, the same problem exists on the latest version of Joomla when using NGINX...
We had the exact same problem on one of our client's sites. The problem turned out to be related to one of PHP's $_SERVER constants not being set by the NGINX server - and that constant (which is `$_SERVER['PHP_SELF']) is used in many places in Joomla to return the current URL. We have described, in details, the problem and how to fix it, here.
if you're using subfolder / virtual hosts, try changing:
# Support Clean (aka Search Engine Friendly) URLs
location / {
try_files $uri $uri/ /index.php?q=$request_uri;
}
To
# Support Clean (aka Search Engine Friendly) URLs
location /subfolder/ {
try_files $uri $uri/ /subfolder/index.php?q=$request_uri;
}
Hello this is my host configuration, wich is working fine with with Joomla 3.6.5 friendly URLs, Ubuntu 16.04 , PHP7 and nginx:
server {
listen 80;
server_name mydomain.com;
root /var/www/html/mydomain;
index index.php index.html index.htm default.html default.htm;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}
}
My solution was to make sure that this part of the php.ini is enabled: cgi.fix_pathinfo = 1. This fixed the problem that $_SERVER['PHP_SELF'] was not set.
I had it disabled by accident.
cgi.fix_pathinfo provides real PATH_INFO/PATH_TRANSLATED support for CGI. PHP's previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Setting this to 1 will cause PHP CGI to fix its paths to conform to the spec. A setting of zero causes PHP to behave as before. Default is 1. You should fix your scripts to use SCRIPT_FILENAME rather than PATH_TRANSLATED. http://php.net/cgi.fix-pathinfo

Nginx + PHP-FPM + FastCGI cache configuration for Magento

Some of you may have already noticed the recent Optimizing Magento For Peak Performance white paper released by Magento a few days ago. Even though it was mainly written for EE users, I believe we can use most of the tips for the Community edition as well.
After a good reading, I went ahead and merged their suggested Nginx + fastcgi/proxy cache config with my standard virtual host config for Magento and a few minor improvements. Here’s what I came up with:
fastcgi_cache_path /tmp/fcgi levels=1:2 keys_zone=MAGE:64m max_size=128m inactive=10h;
server {
listen 99999; ## Nginx port
server_name domain.com www.domain.com;
root /www/magento; ## App folder
index index.php;
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
access_log off;
log_not_found off;
}
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;
}
# Deny access to hidden files
location ~ (/(app/|includes/|/pkginfo/|var/|report/config.xml)|/\.svn/|/.hta.+) {
deny all;
}
# Forward paths like /js/index.php/x.js to relevant handler
location ~ .php/ {
rewrite ^(.*.php)/ $1 last;
}
# Manually purge pages
location ~ /purge(/.*) {
fastcgi_cache_purge MAGE "$scheme$request_method$host$1";
}
location #fcgi_cache {
#if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss
fastcgi_pass unix:/var/spool/phpfpm.sock; ## php-fpm socket
include fastcgi_params;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 60;
fastcgi_read_timeout 60;
fastcgi_buffer_size 4k;
fastcgi_buffers 512 4k;
fastcgi_busy_buffers_size 8k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors off;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_param SCRIPT_NAME /index.php;
#fastcgi_keep_conn on; # NGINX 1.1.14
fastcgi_temp_path /tmp/fcgi2 1 2;
fastcgi_cache MAGE;
#fastcgi_cache_key "$request_method|$http_if_modified_since|$http_if_none_match|$host|$request_uri"; ## Original
fastcgi_cache_key "$scheme$request_method$host$request_uri$http_if_modified_since$http_if_none_match";
#fastcgi_cache_lock on 5s; # NGINX 1.1.12
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-Cache-Status $upstream_cache_status; # Test
}
location #fcgi_nocache {
#if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss
fastcgi_pass unix:/var/spool/phpfpm.sock; ## php-fpm socket
include fastcgi_params;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 60;
fastcgi_read_timeout 60;
fastcgi_buffer_size 4k;
fastcgi_buffers 512 4k;
fastcgi_busy_buffers_size 8k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors off;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_param SCRIPT_NAME /index.php;
#fastcgi_keep_conn on; # NGINX 1.1.14
fastcgi_temp_path /tmp/fcgi2 1 2;
if ($http_cookie !~ "X-Store=1" ) {
add_header Set-Cookie "X-Store=1; path=/";
}
#add_header X-Cache-Status $upstream_cache_status; # Test
}
}
After some tests, the results seem impressive via AB, but I’m really not that confident if they are accurate and if the cache system is fully working as expected. Could someone elaborate what is the actual logic behind #fcgi_cache and #fcgi_nocache and the cookies? Who is actually getting the cached pages? The stale cache doesn’t seems to be working when PHP-FPM is turned off (?). I’m a bit stucked and somewhat confused with the different headers I’m getting.
Suggestions anyone??
this type of config is absolutely useless for magento, they used it only to get maximum "dummy" throughput, and this config logics even breaks in few places.
you would better configure hole-punching full page cache extension, it will reinsert your dynamic blocks and will keep your site always in cache. there must be as well cache refresh for newly added products and qty changes, etc.
I know this is an old question, but in case anybody stumbles upon this thread, I just wanted to point out that the newest Magento releases (>=1.13 enterprise & >=1.8 community) will break this nginx caching method.
Once upgraded, and caching is enabled, your users will no longer be able to add to cart if they are looking at a cached page. The reason behind this, is that Magento added in a url form key for the "Add to Cart" button to prevent cross site scripting. With nginx cache turned on, the first URL form key will be cached, and the next set of users will be loading an invalid form key not attached to their session. As far as I could tell, there isn't a way to hole punch nginx cache either, which (to quote ADM) makes "nginx caching absolutely useless". If anybody out there knows if there IS a way to hole punch nginx cache, I'm all ears.
If you continued to use the nginx cache, I highly recommend seeing how you could stand up without it as disabling it, will save you many headaches when upgrading to the newest Magento release.

Resources