Get the most out of your Centmin Mod LEMP stack
Become a Member

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.

    AKIN SENOL Member

    Oct 17, 2014
    Local Time:
    1:18 AM
    @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...
    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?

    include /usr/local/nginx/conf/wp_fastcgicache.conf;
    # Centmin Mod Getting Started Guide
    # must read
    # For SPDY SSL Setup
    # read
    # 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;
    #    return 302 https://$server_name$request_uri;
    # }
    map $http_host $blogid {
        default       -999;
        include /home/nginx/domains/;  
    server {
      listen 443 ssl http2;
      listen [::]:443 ssl http2;
      ssl_dhparam /usr/local/nginx/conf/ssl/;
      ssl_certificate      /usr/local/nginx/conf/ssl/;
      ssl_certificate_key  /usr/local/nginx/conf/ssl/;
      include /usr/local/nginx/conf/ssl_include.conf;
      http2_max_field_size 16k;
      http2_max_header_size 32k;
      # mozilla recommended
      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 valid=10m;
      #resolver_timeout 10s;
      #ssl_stapling on;
      #ssl_stapling_verify on;
      #ssl_trusted_certificate /usr/local/nginx/conf/ssl/;
    # 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/ combined buffer=256k flush=60m;
      error_log /home/nginx/domains/;
      root /home/nginx/domains/;
    # 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/;
      #include /usr/local/nginx/conf/wpincludes/;
      #include /usr/local/nginx/conf/wpincludes/;
      include /usr/local/nginx/conf/wpincludes/;
      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
      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/;  
        #include /usr/local/nginx/conf/php-wpsc.conf;
        #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;
        #include /usr/local/nginx/conf/php-rediscache.conf;
        include /usr/local/nginx/conf/php-fastcgicache.conf;
      include /usr/local/nginx/conf/wpincludes/;
      #include /usr/local/nginx/conf/php-wpsc.conf;
      #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;
    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" '
    ### 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;
    ## Admin Rewrites
        if (!-e $request_filename) {
                rewrite /wp-admin$ $scheme://$host$uri/ permanent;
                rewrite ^(/[^/]+)?(/wp-.*) $2 last;
                rewrite ^/[^/]+(/.*.php)$ $1 last;
    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;
    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
        location ~ /purge(/.*) {
        fastcgi_cache_purge WPCACHE "$scheme$request_method$host$1";
        return 200;
        deny all;
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass   unix:/tmp/php5-fpm.sock;
        fastcgi_index  index.php;
    # for fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; referenced by
        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

    May 24, 2014
    Brisbane, Australia
    Local Time:
    11:18 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    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 :)
    • Agree Agree x 1

    AKIN SENOL Member

    Oct 17, 2014
    Local Time:
    1:18 AM
    This configuration make php crazy. Php error logs became 40gb :/
    • Informative Informative x 1