nginx 的 wordpress rewrite 规则

我目前在用的 nginx 设置就是这个,已经包含了 WP Super Cache 的 rewrite rule,大部分内容是我搜来的,很不幸暂时找不到来自哪里了…… 其实网上类似的内容太多了~

server {
  listen 80;
  server_name www.example.net;

  location / {
    index index.php;
    root /var/host/wordpress;
    gzip_static on;

    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|wp-postpass_" ) {
      set $supercache_uri '';
    }

    if ($supercache_uri ~ ^(.+)$) {
      set $supercache_file /wp-content/cache/supercache/$http_host/$1index.html;
    }

    if (-f $document_root$supercache_file) {
      rewrite ^(.*)$ $supercache_file break;
    }

    if (!-e $request_filename) {
      rewrite . /index.php last;
    }
  }

  location ~ .*.php5?$ {
    include fastcgi_params;
    root /var/host/wordpress;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass unix:/var/run/php_fcgi.sock;
    fastcgi_index index.php;
  }
}

2 thoughts on “nginx 的 wordpress rewrite 规则

Leave a Reply

Your email address will not be published. Required fields are marked *