Advertisement
pentago

Nginx PHP cache config

Nov 1st, 2015
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nginx 1.42 KB | None | 0 0
  1. #more advanced configuration options and plugin info available here: https://rtcamp.com/wordpress-nginx/tutorials/single-site/fastcgi-cache-with-purging/
  2.  
  3. fastcgi_cache_path /usr/share/nginx/cache/fcgi levels=1:2 keys_zone=microcache:10m max_size=1024m inactive=1h;
  4.  
  5.  
  6.         set $no_cache 0;
  7.         if ($request_method = POST){set $no_cache 1;}
  8.         if ($query_string != \"\"){set $no_cache 1;}
  9.         if ($http_cookie = \"PHPSESSID\"){set $no_cache 1;}
  10.         if ($request_uri ~* \"/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml\") {set $no_cache 1;}
  11.         if ($http_cookie ~* \"comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in\"){set $no_cache 1;}
  12.  
  13. /etc/nginx/sites-available/default
  14.     location / {/
  15.     location ~ .php$ {
  16.         try_files $uri =404;
  17.         fastcgi_split_path_info ^(.+\\\.php)(/.+)$;
  18.         fastcgi_cache  microcache;
  19.         fastcgi_cache_key $scheme$host$request_uri$request_method;
  20.         fastcgi_cache_valid 200 301 302 30s;
  21.         fastcgi_cache_use_stale updating error timeout invalid_header http_500;
  22.         fastcgi_pass_header Set-Cookie;
  23.         fastcgi_no_cache $no_cache;
  24.         fastcgi_cache_bypass $no_cache;
  25.         fastcgi_pass_header Cookie;
  26.         fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
  27.         fastcgi_pass unix:/var/run/php5-fpm.sock;
  28.         fastcgi_index index.php;
  29.         include fastcgi_params;
  30.     }
  31.  
  32. #benchmark from loadimpact: http://loadimpact.com/load-test/69.55.49.190-eabaf77a2ff22ab93bb978a8ecf485cb
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement