server {
  server_name domain.com;
  rewrite ^/(.*) http://www.domain.com/$1 permanent;
}

server {
  server_name  www.domain.com;

  client_max_body_size 8M;
  client_body_buffer_size 256k;

  location / {
    if ($request_method = POST) {
      proxy_pass http://localhost:8000;
      break;
    }

    default_type  "text/html; charset=utf-8";
    set $memcached_key "/budokin-$uri";
    memcached_pass 127.0.0.1:11211;
    error_page 404 502 = /fallback;
  }

  location = /fallback {
    proxy_pass http://127.0.0.1:8000;
    break;
  }

  access_log off;
  #access_log /home/kam/www/budokin.com/log/access.log;
  error_log /home/kam/www/budokin.com/log/error.log;
}

server {
  listen  8000;
  server_name  www.domain.com;
  root  /home/user/domain.com;
  index  index.php;

  client_max_body_size 8M;
  client_body_buffer_size 256k;

  location / {
    if (!-e $request_filename) {
      rewrite ^/action/([A-Za-z\_\-\/] +) /engine/handlers/action_handler.php?action=$1 last;
      rewrite ^/actions/([A-Za-z\_\-\/] +) /engine/handlers/action_handler.php?action=$1 last;
      rewrite ^/export/([A-Za-z] +)/([0-9] +) /services/export/handler.php?view=$1&guid=$2 last;
      rewrite ^/export/([A-Za-z] +)/([0-9] +)/([A-Za-z] +)/([A-Za-z0-9\_] +) /services/export/handler.php?view=$1&guid=$2&type=$3&idname=$4 last;
      rewrite ^/_css/css.css /_css/css.php last;
      rewrite ^/pg/([A-Za-z\_\-] +)/(.*) /engine/handlers/pagehandler.php?handler=$1&page=$2 last;
      rewrite ^/pg/([A-Za-z\_\-] +) /engine/handlers/pagehandler.php?handler=$1 last;
      rewrite ^/xml-rpc.php /engine/handlers/xml-rpc_handler.php last;
      rewrite ^/mt/mt-xmlrpc.cgi /engine/handlers/xml-rpc_handler.php last;
    }
  }

  location ~ \.php$ {
    fastcgi_connect_timeout 60;
    fastcgi_send_timeout 180;
    fastcgi_read_timeout 180;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 4 256k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
    fastcgi_intercept_errors on;

    fastcgi_pass  127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    fastcgi_param  QUERY_STRING     $query_string;
    fastcgi_param  REQUEST_METHOD   $request_method;
    fastcgi_param  CONTENT_TYPE     $content_type;
    fastcgi_param  CONTENT_LENGTH   $content_length;

    expires  max;
  }

  access_log off;
  #access_log /home/kam/www/budokin.com/log/access.log;
  error_log /home/kam/www/budokin.com/log/error.log;

  #error_page  500 502 503 504  /50x.html;
  #location =  /500.html { root  /home/kam/www/nginx-default; }
}
