fastcgi_cache_path /mnt/ramdisk/phpfpm-cache levels=1:2 keys_zone=microcache:5M max_size=1G inactive=2h;

server {
  listen 8080 default;
  server_name _;
  access_log /mnt/access.log;
  error_log /mnt/error.log;
  root   /var/www/;
  index index.php index.html;
  client_max_body_size    10m;
  client_body_buffer_size 128k;
  client_header_buffer_size 64k;

  location = /favicon.ico {
    allow all;
    log_not_found off;
    access_log off;
  }

  location = /robots.txt {
    allow all;
    log_not_found off;
    access_log off;
  }

  location ~* \.(js|css|png|jpg|jpeg|gif|ico|zip|gz|tar)$ {
    log_not_found off;
    access_log off;
    expires max;
  }

  location / {
    try_files $uri $uri/ @memcache;
  }

  location ~ /\. {
    access_log off;
    log_not_found off;
    deny all;
  }

  location ~* /(fpm.www.status|fpm.www.ping)$ {
    include /etc/nginx/fastcgi_params;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param SCRIPT_NAME     $fastcgi_script_name;
    fastcgi_param QUERY_STRING    $args;
  }

  location ~ \.php$ {
    try_files $uri @memcache;
    include /etc/nginx/fastcgi_params;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param SCRIPT_NAME     $fastcgi_script_name;
    fastcgi_param QUERY_STRING    $args;
  }

  # Keeping this in by default. It will _always_ fail for 127.0.0.1 since
  # there is no local memcache server. This might change for the default
  # setup in the future, but for now it's essentially a redirect to @rewrite
  location @memcache {
    default_type text/html;

    set $memcached_key data-$scheme://$host$request_uri;
    memcached_pass 127.0.0.1:11211;
    error_page 404 = @rewrite;
  }

  location @rewrite {
    index index.php;
    include /etc/nginx/fastcgi_params;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_buffers 256 4k;
    fastcgi_intercept_errors on;
    fastcgi_hide_header 'X-Generator';
    fastcgi_read_timeout 14400;
    fastcgi_param SCRIPT_FILENAME $document_root/index.php;
    fastcgi_param SCRIPT_NAME     /index.php;
    fastcgi_param QUERY_STRING    $args;
  }
}
