Advertisement
mikeg_de

Common Wordpress-Configuration for Nginx with FastCGI

Feb 25th, 2014
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. # Find full tutorial at: http://mikeg.de/project/cloud-nginx-server-wordpress/
  2. # wordpress-common.conf
  3. # Set a variable to work around the lack of nested conditionals
  4. set $cache_uri $request_uri;
  5. set $skip_cache 0;
  6.  
  7. if ($query_string != "") {
  8. set $skip_cache 1;
  9. }
  10.  
  11. # Don't cache uris containing the following segments
  12. if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml|\/wp-(app|cron|login|register|mail)\.php|wp\-comments\-popup\.php|wp\-links\-opml\.php|wp\-locations\.php") {
  13. set $skip_cache 1;
  14. }
  15.  
  16. # Don't use the cache for logged in users or recent commenters
  17. if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
  18. set $skip_cache 1;
  19. }
  20.  
  21. location ~ /purge(/.*) {
  22. fastcgi_cache_purge WORDPRESS "$scheme$request_method$host$1";
  23. }
  24.  
  25. location / {
  26. # Use cached or actual file if they exists, otherwise pass request to WordPress
  27. #try_files $uri $uri/ /index.php?q=$uri&$args;
  28. try_files $uri $uri/ /index.php?q=$request_uri;
  29.  
  30. # SECURITY
  31. if ($request_method !~ ^(GET|HEAD|POST)$ ) {
  32. return 444;
  33. }
  34.  
  35. # POST requests and urls with a query string should always go to PHP
  36. if ($request_method = POST) {
  37. set $skip_cache 1;
  38. }
  39.  
  40. # this serves static files that exist without running other rewrite tests
  41. if (-f $request_filename) {
  42. expires 30d; break;
  43. }
  44. }
  45.  
  46. location ~ \.php$ {
  47. fastcgi_cache WORDPRESS;
  48. fastcgi_cache_valid 200 60m;
  49. include fastcgi_params;
  50.  
  51. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  52. # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
  53.  
  54. fastcgi_pass unix:/var/run/php5-fpm.sock;
  55. fastcgi_param SCRIPT_FILENAME $request_filename;
  56.  
  57. fastcgi_cache_bypass $skip_cache;
  58. fastcgi_no_cache $skip_cache;
  59.  
  60. # Note: fastcgi_index is not needed is standard PHP location ~ \.php$ is useed: http://blog.martinfjordvald.com/2011/01/no-input-file-specified-with-php-and-nginx/
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement