[Nginx][WordPress] WordPress リバースプロキシキャッシュ用の nginx.conf

/etc/nginx/php-fpm

try_files $uri =404;

expires        off;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass   unix:/var/run/php-fpm.sock;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
include        fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_busy_buffers_size 32k;
fastcgi_temp_file_write_size 256k;

/etc/nginx/conf.d/default.conf

upstream backend {
  server unix:/var/run/nginx-backend.sock;
}

# reverse proxy
server {
    listen      80 default;
    server_name _;
    root        /path/to/wordpress;
    index       index.html index.htm;
    charset     utf-8;

    access_log  /var/log/nginx/access.log  main;
    error_log   /var/log/nginx/error.log;

    location ~ /\. { deny all; access_log /dev/null; log_not_found off; }

    rewrite /wp-admin$ $scheme://$host$uri/ permanent;

    set $do_not_cache 0;
    if ($http_cookie ~* "comment_author_|wordpress_(?!test_cookie)|wp-postpass_" ) {
        set $do_not_cache 1;
    }
    if ($request_method = POST) {
        set $do_not_cache 1;
    }

    location / {
        try_files $uri @wordpress;

        # Pass all .php files onto a php-fpm/php-fcgi server.
        location ~ \.php$ {
            include /etc/nginx/php-fpm;
        }
    }

    location @wordpress {
        proxy_no_cache     $do_not_cache;
        proxy_cache_bypass $do_not_cache;

        proxy_redirect     off;
        proxy_cache        czone;
        proxy_cache_key    "$scheme://$host$request_uri";
        proxy_cache_valid  200 10m;
        proxy_cache_valid  404 5m;
        proxy_pass     http://backend;
    }

    # 404
    error_page 404 @not_found;
    location @not_found {
        internal;
        rewrite ^ /404;
    }
}

# backend
server {
    listen      unix:/var/run/nginx-backend.sock default;
    server_name _;
    root        /path/to/wordpress;
    index       index.php index.html index.htm;

    access_log  /var/log/nginx/backend.access.log main;

    keepalive_timeout 25;
    port_in_redirect  off;

    gzip              off;
    gzip_vary         off;

    # This order might seem weird - this is attempted to match last if rules below fail.
    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    # Pass all .php files onto a php-fpm/php-fcgi server.
    location ~ \.php$ {
        set $proxy_https '';
        if ( $http_x_forwarded_proto = 'https' ) {
            set $proxy_https 'on';
        }

        include /etc/nginx/php-fpm;
        fastcgi_param  REMOTE_ADDR      $http_x_real_ip;
        fastcgi_param  HTTPS            $proxy_https  if_not_empty;
        fastcgi_pass_header "X-Accel-Redirect";
        fastcgi_pass_header "X-Accel-Buffering";
        fastcgi_pass_header "X-Accel-Charset";
        fastcgi_pass_header "X-Accel-Expires";
        fastcgi_pass_header "X-Accel-Limit-Rate";
    }
}

Re: How do I extend fetch_feed timeout?

As a quick fix I just went straight for the SimplePie code that the WordPress code is wrapping around.

$feed = new SimplePie();
$feed->set_feed_url('http://rss.betfair.com/RSS.aspx?format=rss&sportID=7');
$feed->set_timeout(30); // set to 30 seconds
$feed->set_item_limit(40);
$feed->set_stupidly_fast(true);
$feed->enable_cache(true);
$feed->set_cache_duration(200);
$feed->init();
$feed->handle_content_type();

WordPress › Support » How do I extend fetch_feed timeout?

WordPress の fetch_feed() 関数でタイムアウト値を延ばす方法をググったらサポートのこの回答が出てきたんだけど、wp-includes/feed.php 眺めたら、アクションフックがあったので、こっちで対応できるねというお話。

add_action('wp_feed_options', function(&$feed, $url){
    $feed->set_timeout(30); // set to 30 seconds
}, 10, 2);

今日の教訓:ググる前にソースを見よう。

[WordPress] WP_ALLOW_REPAIR の罠

http://example.com/wp-admin/maint/repair.php を有効にするには wp-config.php に以下を追記します。

define('WP_ALLOW_REPAIR', true);

これを無効にしようとして define('WP_ALLOW_REPAIR', false); としてもダメです。コメントアウトするか行自体を削除しないといけない。
なぜなら wp-admin/maint/repair.php で以下のように判定してるから。

 :
if ( ! defined( 'WP_ALLOW_REPAIR' ) ) {
        echo '

' . __( 'To allow use of this page to automatically repair database problems, please add the following line to your wp-config.php file. Once this line is added to your config, reload this page.' ) . "

define('WP_ALLOW_REPAIR', true);

"; } elseif ( isset( $_GET['repair'] ) ) { :

ママン、設定値の名前にだまされたよ。