Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Thu Dec 01, 2011 12:53 pm 
Offline
Junior Member

Joined: Fri Nov 11, 2011 11:07 pm
Posts: 22
Hello i am trying to configure nginx to work with WP Supercache. First of all i am using the latest stable version of WP Super Cache which is 0.9.9.9 and this is the .htaccess rules WP Super Cache gives me on its plugin page;
Code:
    # BEGIN WPSuperCache
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    AddDefaultCharset UTF-8
    RewriteCond %{REQUEST_METHOD} !POST
    RewriteCond %{QUERY_STRING} !.*=.*
    RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$
    RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\"]+ [NC]
    RewriteCond %{HTTP:Profile} !^[a-z0-9\"]+ [NC]
    RewriteCond %{HTTP:Accept-Encoding} gzip
    RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz -f
    RewriteRule ^(.*) "/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz" [L]
   
    RewriteCond %{REQUEST_METHOD} !POST
    RewriteCond %{QUERY_STRING} !.*=.*
    RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$
    RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\"]+ [NC]
    RewriteCond %{HTTP:Profile} !^[a-z0-9\"]+ [NC]
    RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html -f
    RewriteRule ^(.*) "/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html" [L]
    </IfModule>
    # END WPSuperCache


So according to that; i am now going to post 2 wp super cache configs. If you help me to decide which one i should use i will be very glad. Also you can help me to improve my codes for best use. First of all i am going to post my nginx.conf. Here it is;

Code:
    user www-data www-data;
   
    worker_processes     4;
   
    error_log  /var/log/nginx/error.log;
    pid        /var/run/nginx.pid;
   
    events {
        worker_connections  1024;
    }
     
    http {
        # General Settings
        gzip  on;
        sendfile on;
        tcp_nopush on;
        tcp_nodelay off;
        server_tokens off;
        include mime.types;
        keepalive_timeout 65;
        default_type  application/octet-stream;
     
        # If we set index here, we won't have to anywhere else
        index index.php index.html index.htm;
       
        upstream php {
        server unix:/tmp/php5-fpm.sock;
        }
   
        fastcgi_intercept_errors off;
   
        include sites-enabled/*;
    }


Here is my restrictions.conf;

Code:
    location = /robots.txt  { access_log off; log_not_found off; }
    location = /favicon.ico { access_log off; log_not_found off; }
    location ~ /\.          { access_log off; log_not_found off; deny all; }
    location ~ ~$           { access_log off; log_not_found off; deny all; }


And now i am going to post my two different domain.com configuration setups. They also include supercache related configs. Here is number 1;
Code:

    server {
          listen 80;
          server_name www.domain.com domain.com;
          root /srv/www/domain.com/public_html;
   
          access_log off;
          error_log /srv/www/domain.com/logs/error.log;
   
          if ($http_host != "domain.com") {
          rewrite ^ http://domain.com$request_uri permanent;
          }
     
          location / {
          gzip_static      on;
          gzip_disable      "MSIE [1-6]\.";
          gzip_buffers      16 8k;
          gzip_comp_level   3;
          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 image/png image/gif image/jpeg;
          gzip_proxied      any;
     
          if (-f $request_filename) { break; }
     
          set $supercache_file '';
          set $supercache_uri $request_uri;
     
          if ($request_method = POST) { set $supercache_uri ''; }
          if ($query_string) { set $supercache_uri ''; }
          if ($http_cookie ~* "comment_author_|wordpress_logged_in|wp-postpass_" ) {
             set $supercache_uri '';
          }
     
          if ($supercache_uri ~ ^(.+)$) {
             set $supercache_file /wp-content/cache/supercache/${http_host}${uri}index.html;
          }
     
          if (-f $document_root$supercache_file) { rewrite ^ $supercache_file break; }
     
          if (!-e $request_filename) { rewrite ^ /index.php last; }
          }
     
          fastcgi_intercept_errors off;
     
          location ~* \.(?:ico|css|js|gif|jpeg|jpg|png)$ {
          expires max;
          add_header Pragma public;
          add_header Cache-Control "public, must-revalidate, proxy-revalidate";
          }
          
          # Add trailing slash to */wp-admin requests.
          rewrite /wp-admin$ $scheme://$host$uri/ permanent;
     
          # Pass all .php files onto a php-fpm/php-fcgi server.
          location ~ \.php$ {
          try_files $uri =404;
          fastcgi_split_path_info ^(.+\.php)(/.+)$;
          include fastcgi_params;
          fastcgi_index index.php;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          fastcgi_pass php;
          }
     
          include restrictions.conf;
       }


And here is my domain.com number 2 setup;

Code:
    server {
          listen 80;
            server_name www.domain.com domain.com;
            root /srv/www/domain.com/public_html;
   
            access_log off;
            error_log /srv/www/domain.com/logs/error.log;
   
            if ($http_host != "domain.com") {
            rewrite ^ http://domain.com$request_uri permanent;
            }
     
          location / {
          gzip_static      on;
          gzip_disable      "MSIE [1-6]\.";
          gzip_buffers      16 8k;
          gzip_comp_level   3;
          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 image/png image/gif image/jpeg;
          gzip_proxied      any;
     
          if ($request_uri ~ ^.*//.*$) {
          return 405;
          }
   
          if ($request_method ~ POST) {
          return 405;
          }
   
          if ($query_string ~ ^.*=.*$) {
          return 405;
          }
          if ($query_string ~ ^.*attachment_id=.*$) {
          return 405;
          }
   
          if ($http_cookie ~ (?:comment_author_|wordpress_logged_in|wp-postpass_)) {
          return 405;
          }
   
          if ($http_x_wap_profile ~ ^[a-z0-9\"]+) {
          return 405;
          }
   
          if ($http_profile ~ ^[a-z0-9\"]+) {
          return 405;
          }
   
          if ($http_user_agent ~ ^.*(?:2.0\ MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800).*) {
          return 405;
          }
          
          if ($http_user_agent ~ ^(w3c\ |w3c-|acs-|alav|alca|amoi|audi|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-|dang|doco|eric|hipt|htc_|inno|ipaq|ipod|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-|lg/u|maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|palm|pana|pant|phil|play|port|prox|qwap|sage|sams|sany|sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo|teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|wap-|wapa|wapi|wapp|wapr|webc|winw|winw|xda\ |xda-).*) {
          return 405;
          }
   
          error_page 405 = @nocache;
   
          try_files /wp-content/cache/supercache/${http_host}${uri}index.html $uri $uri/ /index.php?q=$uri&$args;
          }
     
          fastcgi_intercept_errors off;
     
          location ~* \.(?:ico|css|js|gif|jpeg|jpg|png)$ {
          expires max;
          add_header Pragma public;
          add_header Cache-Control "public, must-revalidate, proxy-revalidate";
          }
          
          # Add trailing slash to */wp-admin requests.
          rewrite /wp-admin$ $scheme://$host$uri/ permanent;
     
          # Pass all .php files onto a php-fpm/php-fcgi server.
          location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            include fastcgi_params;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_pass php;
          }
     
          include restrictions.conf;
       }


So what do you think? Are there any errors? Which one do you suggest me to use? Also is this correct;

Code:
try_files /wp-content/cache/supercache/${http_host}${uri}index.html $uri $uri/ /index.php?q=$uri&$args;


according to this;

Code:
RewriteRule ^(.*) "/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz" [L]


And one last question; as you see wp supercache creates htaccess rules like index.html.gz not index.html so according to this should i change

Code:
/wp-content/cache/supercache/${http_host}${uri}index.html


to

Code:
/wp-content/cache/supercache/${http_host}${uri}index.html.gz


Thank you in advance.

Notes:
1-I have static gzip module compiled in with nginx.
2-There are one index.html and one index.html.gz files in my created cache folders.
3-I set cgi.fix_pathinfo to 0 in the php.ini


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group