Guest User

NGINX Server block with FastCGI Purge

a guest
Feb 27th, 2014
186
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fastcgi_cache_path /etc/nginx/cache/abc levels=1:2 keys_zone=ABC:100m inactive=60m;
  2. add_header X-Cache $upstream_cache_status;
  3.  
  4. server {
  5. listen 80; ## listen for ipv4; this line is default and implied
  6.  
  7. root /var/www/abc/public_html;
  8. index index.php index.html index.htm;
  9.  
  10. server_name abc.com www.abc.com;
  11.  
  12. location / {
  13. try_files $uri $uri/ /index.php?q=$uri&$args;
  14.  
  15.  
  16. # FastCGI Rules
  17. set $no_cache 0;
  18. if ($request_method = POST) {
  19. set $no_cache 1;
  20. }
  21.  
  22. if ($query_string != "") {
  23. set $no_cache 1;
  24. }
  25.  
  26. if ($request_uri ~* "(/admin.php|/admin/|/adminitrator|/login.php|/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
  27. set $no_cache 1;
  28. }
  29.  
  30. if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
  31. set $no_cache 1;
  32. }
  33.  
  34. #Don't cache if there is a cookie called PHPSESSID
  35. if ($http_cookie = "PHPSESSID")
  36. {
  37. set $no_cache 1;
  38. }
  39.  
  40. }
  41.  
  42. location /doc/ {
  43. alias /usr/share/doc/;
  44. autoindex on;
  45. allow 127.0.0.1;
  46. deny all;
  47. }
  48.  
  49. error_page 404 /404.html;
  50. error_page 500 502 503 504 /50x.html;
  51. location = /50x.html {
  52. root /usr/share/nginx/www;
  53. }
  54.  
  55. location ~ \.php$ {
  56. try_files $uri =404;
  57. fastcgi_pass unix:/var/run/php5-fpm.sock;
  58. fastcgi_index index.php;
  59. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  60. include fastcgi_params;
  61. fastcgi_cache ABC;
  62. fastcgi_cache_valid 200 60m;
  63. fastcgi_cache_bypass $no_cache;
  64. fastcgi_no_cache $no_cache;
  65. fastcgi_cache_key "$scheme$request_method$host$request_uri";
  66. fastcgi_cache_use_stale error timeout invalid_header http_500;
  67.  
  68. }
  69.  
  70.  
  71. # Purge settings
  72. location ~ /purge(/.*) {
  73. fastcgi_cache_purge ABC "$scheme$request_method$host$1";
  74. }
  75.  
  76. 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)$ {
  77. access_log off; log_not_found off; expires max;
  78. }
  79.  
  80. location = /robots.txt { access_log off; log_not_found off; }
  81. location ~ /\. { deny all; access_log off; log_not_found off; }
  82.  
  83.  
  84. #Header Expiry
  85. location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
  86. access_log off;
  87. log_not_found off;
  88. expires 360d;
  89. }
  90.  
  91. }
RAW Paste Data