Discover Centmin Mod today
Register Now

Wordpress Multisite/subdir with fastcgi cache under new hierarchy

Discussion in 'Blogs & CMS usage' started by AKIN SENOL, Mar 27, 2016.

  1. fastcgi + ngx_pagespeed

  2. fastcgi + plugin like autoptimize

  3. redis nginx level caching + redis object cache

  4. fastcgi + ngx_pagespeed + redis object cache

  5. wp supercache / wp cache enabler or other plugin like this

  6. fastcgi + memcached

Results are only viewable after voting.
  1. AKIN SENOL

    AKIN SENOL Member

    36
    3
    8
    Oct 17, 2014
    London
    Ratings:
    +8
    Local Time:
    6:42 PM
    1.9.12
    10.1.12
    @eva2000 I included some line for a multisite/subdir fastcgi config with new hierarchy but frontend source code doesn't include nginx helper timestamp and there is no error in log files right now.


    Edit: There is a error in php logs, so fastcgi doesn't work well and needs to php handle...
    Code:
    WARNING: [pool www] server reached max_children setting (4), consider raising it
    So guys I'm not sure it's working properly, what's your opinion with below configuration?

    Full example.com.ssl.conf
    Code:
    include /usr/local/nginx/conf/wp_fastcgicache.conf;
    
    # Centmin Mod Getting Started Guide
    # must read http://centminmod.com/getstarted.html
    # For SPDY SSL Setup
    # read http://centminmod.com/nginx_configure_https_ssl_spdy.html
    
    # redirect from www to non-www  forced SSL
    # uncomment, save file and restart Nginx to enable
    # if unsure use return 302 before using return 301
    # server {
    #   server_name example.com www.example.com;
    #    return 302 https://$server_name$request_uri;
    # }
    map $http_host $blogid {
        default       -999;
        include /home/nginx/domains/example.com/public/wp-content/uploads/nginx-helper/map.conf;  
        }
    
    server {
      listen 443 ssl http2;
      listen [::]:443 ssl http2;
      server_name example.com www.example.com;
    
      ssl_dhparam /usr/local/nginx/conf/ssl/example.com/dhparam.pem;
      ssl_certificate      /usr/local/nginx/conf/ssl/example.com/example.com.crt;
      ssl_certificate_key  /usr/local/nginx/conf/ssl/example.com/example.com.key;
      include /usr/local/nginx/conf/ssl_include.conf;
    
      http2_max_field_size 16k;
      http2_max_header_size 32k;
      # mozilla recommended
      ssl_ciphers EECDH+CHACHA20-draft:EECDH+CHACHA20:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA:!CAMELLIA:!DES-CBC3-SHA;
      ssl_prefer_server_ciphers   on;
      add_header Alternate-Protocol  443:npn-spdy/3;
      # HTTP Public Key Pinning Header uncomment only one that applies include or exclude domains.
      # You'd want to include subdomains if you're using SSL wildcard certificates
      # include subdomain
      add_header Public-Key-Pins 'pin-sha256="khCnBS93Z8GCqLoKXimMM0pjxCnwlaxyw2zp/szHL5Y="; pin-sha256="ONZwMFhVhWUVZ/qyZ/CKATOQ4mfPl95Ad06+BkTL+20="; max-age=15552000; includeSubDomains';
      # exclude subdomains
      #add_header Public-Key-Pins 'pin-sha256="khCnBS93Z8GCqLoKXimMM0pjxCnwlaxyw2zp/szHL5Y="; pin-sha256="ONZwMFhVhWUVZ/qyZ/CKATOQ4mfPl95Ad06+BkTL+20="; max-age=86400';
      add_header Strict-Transport-Security "max-age=31536000; includeSubdomains;";
      add_header X-Frame-Options SAMEORIGIN;
      add_header X-Xss-Protection "1; mode=block" always;
      add_header X-Content-Type-Options "nosniff" always;
      #spdy_headers_comp 5;
      ssl_buffer_size 1400;
      ssl_session_tickets on;
    
      # enable ocsp stapling
      #resolver 8.8.8.8 8.8.4.4 valid=10m;
      #resolver_timeout 10s;
      #ssl_stapling on;
      #ssl_stapling_verify on;
      #ssl_trusted_certificate /usr/local/nginx/conf/ssl/example.com/example.com-trusted.crt;
    
    # ngx_pagespeed & ngx_pagespeed handler
    #include /usr/local/nginx/conf/pagespeed.conf;
    #include /usr/local/nginx/conf/pagespeedhandler.conf;
    #include /usr/local/nginx/conf/pagespeedstatslog.conf;
    
      #add_header X-Frame-Options SAMEORIGIN;
      #add_header X-Xss-Protection "1; mode=block" always;
      #add_header X-Content-Type-Options "nosniff" always;
    
      # limit_conn limit_per_ip 16;
      # ssi  on;
    
      access_log /home/nginx/domains/example.com/log/access.log combined buffer=256k flush=60m;
      error_log /home/nginx/domains/example.com/log/error.log;
    
      root /home/nginx/domains/example.com/public;
    
    # aio threads;
    
      # uncomment cloudflare.conf include if using cloudflare for
      # server and/or vhost site
      include /usr/local/nginx/conf/cloudflare.conf;
      include /usr/local/nginx/conf/503include-main.conf;
    
      # prevent access to ./directories and files
      location ~ (?:^|/)\. {
       deny all;
      }
    
       include /usr/local/nginx/conf/multisite-admin-rw.conf;
    
      #include /usr/local/nginx/conf/wpincludes/example.com/wpcacheenabler_example.com.conf;
      #include /usr/local/nginx/conf/wpincludes/example.com/wpsupercache_example.com.conf;
      # https://community.centminmod.com/posts/18828/
      #include /usr/local/nginx/conf/wpincludes/example.com/rediscache_example.com.conf;
      include /usr/local/nginx/conf/wpincludes/example.com/fastcgicache_example.com.conf;
    
      location / {
      include /usr/local/nginx/conf/503include-only.conf;
    
      # Enables directory listings when index file not found
      #autoindex  on;
    
      # for wordpress super cache plugin
      ###try_files /wp-content/cache/supercache/$http_host/$cache_uri/index.html $uri $uri/ /index.php?q=$uri&$args;
    
      # for wp cache enabler plugin
      #try_files $cache_enabler_uri $uri $uri/ $custom_subdir/index.php?$args;
    
      # Wordpress Permalinks
      #try_files $uri $uri/ /index.php?q=$uri&$args;
    
      # Nginx level redis Wordpress
      # https://community.centminmod.com/posts/18828/
      try_files $uri $uri/ /index.php?$args;
      }
    
      include /usr/local/nginx/conf/multisite-permalinks.conf;
    
    location ~* /(wp-login\.php) {
        limit_req zone=xwplogin burst=5 nodelay;
        #limit_conn xwpconlimit 30;
        #auth_basic "Private";
        #auth_basic_user_file /home/nginx/domains/example.com/htpasswd_wplogin;  
        #include /usr/local/nginx/conf/php-wpsc.conf;
        # https://community.centminmod.com/posts/18828/
        #include /usr/local/nginx/conf/php-rediscache.conf;
        include /usr/local/nginx/conf/php-fastcgicache.conf;
    
    }
    
    location ~* /(xmlrpc\.php) {
        limit_req zone=xwprpc burst=45 nodelay;
        #limit_conn xwpconlimit 30;
        #include /usr/local/nginx/conf/php-wpsc.conf;
        # https://community.centminmod.com/posts/18828/
        #include /usr/local/nginx/conf/php-rediscache.conf;
        include /usr/local/nginx/conf/php-fastcgicache.conf;
    
    }
    
      include /usr/local/nginx/conf/wpincludes/example.com/wpsecure_example.com.conf;
      #include /usr/local/nginx/conf/php-wpsc.conf;
      # https://community.centminmod.com/posts/18828/
      #include /usr/local/nginx/conf/php-rediscache.conf;
      include /usr/local/nginx/conf/php-fastcgicache.conf;
      include /usr/local/nginx/conf/staticfiles.conf;
      include /usr/local/nginx/conf/drop.conf;
      #include /usr/local/nginx/conf/errorpage.conf;
      include /usr/local/nginx/conf/vts_server.conf;
    }
    
    wp_fastcgicache.conf
    Code:
    fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=WPCACHE:256m max_size=512m inactive=50m;
    fastcgi_cache_key "$scheme$request_method$host$request_uri";
    fastcgi_cache_use_stale error timeout invalid_header http_500;
    
    log_format cache '$remote_addr - $remote_user [$time_local]  '
                      '"$request" $status $body_bytes_sent '
                      '"$http_referer" "$http_user_agent" '
                      '$upstream_cache_status';
    
    ### Map Mobile
    #map $http_user_agent $is_mobile {
    #    default 0;
    #    ~*android|ip(hone|od)|windows\s+(?:ce|phone) 1;
    #    ~*symbian|sonyericsson|samsung|lg|blackberry 1;
    #    ~*mobile 1;
    #}
    multisite-admin-rw.conf
    Code:
    ## Admin Rewrites
        if (!-e $request_filename) {
                rewrite /wp-admin$ $scheme://$host$uri/ permanent;
                rewrite ^(/[^/]+)?(/wp-.*) $2 last;
                rewrite ^/[^/]+(/.*.php)$ $1 last;
        }
    multisite-permalinks.conf
    Code:
    if (-f $request_filename/index.html){
                    rewrite (.*) $1/index.html break;
        }
    
        if (-f $request_filename/index.php){
                    rewrite (.*) $1/index.php;
        }
        if (!-f $request_filename){
                    rewrite (.*) /index.php;
        }
    fastcgicache_example.com.conf
    Code:
    set $skip_cache 0;
    
    # POST requests and urls with a query string should always go to PHP
    if ($request_method = POST) {
      set $skip_cache 1;
    }
    
    if ($query_string != "") {
      set $skip_cache 1;
    }
    
    # Don't cache uris containing the following segments
    if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
      set $skip_cache 1;
    }
    
    # Don't use the cache for logged in users or recent commenters
    if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
      set $skip_cache 1;
    }
    
    # Centmin Mod Nginx has nginx_cache_purge module
    # added http://centminmod.com/nginx.html
        location ~ /purge(/.*) {
        fastcgi_cache_purge WPCACHE "$scheme$request_method$host$1";
        return 200;
        allow 127.0.0.1;
        deny all;
        } 
    php-fastcgicache.conf
    Code:
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        #fastcgi_pass   127.0.0.1:9000;
        fastcgi_pass   unix:/tmp/php5-fpm.sock;
        fastcgi_index  index.php;
    # for fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; referenced by http://codex.wordpress.org/Nginx
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        #fastcgi_param  SCRIPT_FILENAME    $request_filename;
        fastcgi_param PHP_ADMIN_VALUE open_basedir=$document_root/:/usr/local/lib/php/:/tmp/;
    
    # might shave 200+ ms off PHP requests
    # which don't pass on a content length header
    # slightly faster page response time at the
    # expense of throughput / scalability
    sendfile on;
    tcp_nopush off;
    keepalive_requests 0;
    
    fastcgi_connect_timeout 60;
    fastcgi_send_timeout 180;
    fastcgi_read_timeout 180;
    fastcgi_buffer_size 512k;
    fastcgi_buffers 512 16k;
    fastcgi_busy_buffers_size 1m;
    fastcgi_temp_file_write_size 4m;
    fastcgi_max_temp_file_size 4m;
    #fastcgi_intercept_errors on;
    
    # next 3 lines when uncommented / enabled
    # allow Nginx to handle uploads which then
    # passes back the completed upload to PHP
    fastcgi_pass_request_body off;
    client_body_in_file_only clean;
    fastcgi_param  REQUEST_BODY_FILE  $request_body_file;
    
    #new .04+ map method
    fastcgi_param HTTPS $server_https;
    
    # comment out PATH_TRANSLATED line if /usr/local/lib/php.ini sets following:
    # cgi.fix_pathinfo=0
    # as of centminmod v1.2.3-eva2000.01 default is set to cgi.fix_pathinfo=1
    
    fastcgi_param  PATH_INFO          $fastcgi_path_info;
    fastcgi_param  PATH_TRANSLATED    $document_root$fastcgi_path_info;
    
    fastcgi_param  QUERY_STRING       $query_string;
    fastcgi_param  REQUEST_METHOD     $request_method;
    fastcgi_param  CONTENT_TYPE       $content_type;
    fastcgi_param  CONTENT_LENGTH     $content_length;
    
    fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
    fastcgi_param  REQUEST_URI        $request_uri;
    fastcgi_param  DOCUMENT_URI       $document_uri;
    fastcgi_param  DOCUMENT_ROOT      $document_root;
    fastcgi_param  SERVER_PROTOCOL    $server_protocol;
    fastcgi_param  REQUEST_SCHEME     $scheme;
    fastcgi_param  HTTPS              $https if_not_empty;
    
    fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
    fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;
    
    fastcgi_param  REMOTE_ADDR        $remote_addr;
    fastcgi_param  REMOTE_PORT        $remote_port;
    fastcgi_param  SERVER_ADDR        $server_addr;
    fastcgi_param  SERVER_PORT        $server_port;
    fastcgi_param  SERVER_NAME        $server_name;
    
    # Set php-fpm geoip variables
    fastcgi_param GEOIP_COUNTRY_CODE $geoip_country_code;
    fastcgi_param GEOIP_COUNTRY_CODE3 $geoip_country_code3;
    fastcgi_param GEOIP_COUNTRY_NAME $geoip_country_name;
    fastcgi_param GEOIP_CITY_COUNTRY_CODE $geoip_city_country_code;
    fastcgi_param GEOIP_CITY_COUNTRY_CODE3 $geoip_city_country_code3;
    fastcgi_param GEOIP_CITY_COUNTRY_NAME $geoip_city_country_name;
    fastcgi_param GEOIP_REGION $geoip_region;
    fastcgi_param GEOIP_CITY $geoip_city;
    fastcgi_param GEOIP_POSTAL_CODE $geoip_postal_code;
    fastcgi_param GEOIP_CITY_CONTINENT_CODE $geoip_city_continent_code;
    fastcgi_param GEOIP_LATITUDE $geoip_latitude;
    fastcgi_param GEOIP_LONGITUDE $geoip_longitude;
    
    # PHP only, required if PHP was built with --enable-force-cgi-redirect
    fastcgi_param  REDIRECT_STATUS    200;
             fastcgi_cache WPCACHE;
             fastcgi_cache_valid  200 302 2m;
             fastcgi_cache_valid  301 1h;
             fastcgi_cache_valid  any 2m;
             fastcgi_cache_min_uses  1;
             add_header X-Cached $upstream_cache_status;
                       }
    
    Thanks in advance for all contributions
     
    Last edited: Mar 27, 2016
  2. eva2000

    eva2000 Administrator Staff Member

    55,239
    12,253
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,833
    Local Time:
    3:42 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Unfortunately, I have never used wordpress multi-site ever, so apache or nginx configs for them are foreign to me heh. Maybe other folks would have more advice :)
     
  3. AKIN SENOL

    AKIN SENOL Member

    36
    3
    8
    Oct 17, 2014
    London
    Ratings:
    +8
    Local Time:
    6:42 PM
    1.9.12
    10.1.12
    This configuration make php crazy. Php error logs became 40gb :/