Welcome to Centmin Mod Community
Become a Member

Wordpress How to Enable FCGI Cache on WordPress ?

Discussion in 'Blogs & CMS usage' started by Yohan, Oct 2, 2015.

Tags:
  1. Yohan

    Yohan Member

    68
    3
    8
    Sep 24, 2015
    Ratings:
    +4
    Local Time:
    2:16 AM
    1.9.x
    MariaDB 10
    Hello ,

    I'm again .. :D actually i was fallow the tutorial on FCGI Cache .. but its won't work .. i just install your latast MOD .. Please help me by steps by steps as much as easy to way to do :) thanks
     
  2. eva2000

    eva2000 Administrator Staff Member

    34,638
    7,656
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +11,774
    Local Time:
    6:46 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    Last edited: Oct 2, 2015
  3. Yohan

    Yohan Member

    68
    3
    8
    Sep 24, 2015
    Ratings:
    +4
    Local Time:
    2:16 AM
    1.9.x
    MariaDB 10
    Yes i was fallow that tetorial but when after restart "nprestart" Nginx wont start ...
     
  4. eva2000

    eva2000 Administrator Staff Member

    34,638
    7,656
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +11,774
    Local Time:
    6:46 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    post contents of your nginx vhost domain.com.conf file for wordpress and also check your nginx error logs as per faq item 19
     
  5. Yohan

    Yohan Member

    68
    3
    8
    Sep 24, 2015
    Ratings:
    +4
    Local Time:
    2:16 AM
    1.9.x
    MariaDB 10
    Code:
    Centmin Mod Getting Started Guide
    # must read http://centminmod.com/getstarted.html
    
    # redirect from non-www to www
    # uncomment, save file and restart Nginx to enable
    # if unsure use return 302 before using return 301
    #server {
    #  listen  80;
    #  server_name mydomain.info;
    #  return 301 $scheme://www.mydomain.info$request_uri;
    #  }
    
    server {
      server_name mydomain.info www.mydomain.info;
    
    # 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;
    
      # limit_conn limit_per_ip 16;
      # ssi  on;
    
      access_log /home/nginx/domains/mydomain.info/log/access.log combined buffer=256k flush=60m;
      error_log /home/nginx/domains/mydomain.info/log/error.log;
    
      root /home/nginx/domains/mydomain.info/public;
      # prevent access to ./directories and files
      location ~ (?:^|/)\. {
      deny all;
      }
    
    #include /usr/local/nginx/conf/wpsupercache_mydomain.info.conf;
    
      location / {
    
      # 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;
    
      # Wordpress Permalinks
     try_files $uri $uri/ /index.php?q=$uri&$args;
    
      }
    location ~* /(wp-login\.php) {
      limit_req zone=xwplogin burst=1 nodelay;
      #limit_conn xwpconlimit 30;
      auth_basic "Private";
      auth_basic_user_file /home/nginx/domains/mydomain.info/htpasswd_wplogin;
      include /usr/local/nginx/conf/php-wpsc.conf;
    }
    
    location ~* /(xmlrpc\.php) {
      limit_req zone=xwplogin burst=2 nodelay;
      #limit_conn xwpconlimit 30;
      include /usr/local/nginx/conf/php-wpsc.conf;
    }
    
      include /usr/local/nginx/conf/wpsecure_mydomain.info.conf;
      include /usr/local/nginx/conf/php-wpsc.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;
      include /usr/local/nginx/conf/block.conf;
    }
     
    Here is
     
  6. eva2000

    eva2000 Administrator Staff Member

    34,638
    7,656
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +11,774
    Local Time:
    6:46 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
  7. Yohan

    Yohan Member

    68
    3
    8
    Sep 24, 2015
    Ratings:
    +4
    Local Time:
    2:16 AM
    1.9.x
    MariaDB 10
    Actually i was did all steps .. but its wont work ..

    can you provide me correct vHost example ?
     
  8. eva2000

    eva2000 Administrator Staff Member

    34,638
    7,656
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +11,774
    Local Time:
    6:46 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
  9. Yohan

    Yohan Member

    68
    3
    8
    Sep 24, 2015
    Ratings:
    +4
    Local Time:
    2:16 AM
    1.9.x
    MariaDB 10
    Let me update my codes :

    /usr/local/nginx/conf/nginx.conf

    Code:
    user  nginx nginx;
    worker_processes 3;
    worker_priority -10;
    
    worker_rlimit_nofile 260000;
    timer_resolution 100ms;
    
    pcre_jit on;
    
    pid  logs/nginx.pid;
    
    events {
      worker_connections  4096;
      accept_mutex on;
      accept_mutex_delay 200ms;
      use epoll;
      #multi_accept on;
    }
    
    http {
    limit_req_zone $binary_remote_addr zone=xwplogin:16m rate=40r/m;
    #limit_conn_zone $binary_remote_addr zone=xwpconlimit:16m;
    
    more_set_headers "Server: nginx centminmod";
    include /usr/local/nginx/conf/wp_fastcgicache.conf;  <---- i added this  as new
    include /usr/local/nginx/conf/vts_http.conf;
    include /usr/local/nginx/conf/geoip.conf;
    include /usr/local/nginx/conf/pagespeedadmin.conf;
    include /usr/local/nginx/conf/fastcgi_param_https_map.conf;
    
    log_format  main  '$remote_addr - $remote_user [$time_local] $request '
      '"$status" $body_bytes_sent "$http_referer" '
      '"$http_user_agent" "$http_x_forwarded_for" "$gzip_ratio"'
      ' "$connection" "$connection_requests" "$request_time"';
    
    access_log  logs/access.log combined buffer=128k flush=5m;
    error_log  logs/error.log warn;
    
    
    /usr/local/nginx/conf/wpsecure.conf
    Code:
    # Deny access to any files with a .php extension in the uploads directory
    # Works in sub-directory installs and also in multisite network
    location ~* /(?:uploads|files)/.*\.php$ {
    deny all;
    }
    
    # Make sure files with the following extensions do not get loaded by nginx because nginx would display the source code, and these files can contain PASSWORDS!
    location ~* \.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(\..*|Entries.*|Repository|Root|Tag|Template)$|\.php_
    {
    return 444;
    }
    
    #nocgi
    location ~* \.(pl|cgi|py|sh|lua)\$ {
    return 444;
    }
    
    #disallow
    location ~* (roundcube|webdav|smtp|http\:|soap|w00tw00t) {
    return 444;
    }
    
    location ~ /(\.|wp-config\.php|readme\.html|license\.txt) { deny all; }
    
    
    
    /usr/local/nginx/conf/wpcache.conf
    Code:
    #fastcgi_cache start
    set $no_cache 0;
    
    # POST requests and urls with a query string should always go to PHP
    if ($request_method = POST) {
    set $no_cache 1;
    }
    if ($query_string != "") {
    set $no_cache 1;
    }
    
    # Don't cache uris containing the following segments
    # If wordpress installed in subdirectory i.e. /wordpress
    # meed tp add /wordpress in front of /(memcache\.php
    # i.e. if ($request_uri ~* "/wordpress/(memcache\.php
    if ($request_uri ~* "/(memcache\.php|apc\.php|wp-admin/.*|xmlrpc\.php|wp-(app|cron|login|register|mail)\.php|wp-.*\.php|feed/|index\.php|wp-comments-popup\.php|wp-links-opml\.php|wp-locations\.php|sitemap(_index)?\.xml|[a-z0-9_-]+-sitemap([0-9]+)?\.xml)") {
    set $no_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|wordpress-sec") {
    set $no_cache 1;
    }
    
    # Add trailing slash to */wp-admin requests.
    rewrite /wp-admin$ $scheme://$host$uri/ permanent;
    
    # 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;
    }
    
    /usr/local/nginx/conf/wpnocache.conf
    Code:
    # Add trailing slash to */wp-admin requests.
    rewrite /wp-admin$ $scheme://$host$uri/ permanent;
    
    /usr/local/nginx/conf/phpwpcache.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;
      #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_bypass $no_cache $is_mobile;
      fastcgi_no_cache $no_cache $is_mobile;
      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;
    
    
      }
    
    
    so my VHOST Should Like this ?
    Code:
    server {
    # listen 80;
    listen 80 default_server;
    server_name mydomain.info www.mydomain.info;
    root html;
    
    access_log /var/log/nginx/localhost.access.log main buffer=32k;
    error_log /var/log/nginx/localhost.error.log error;
    access_log /var/log/nginx/access.cache.log cache;
    
    # ngx_pagespeed & ngx_pagespeed handler
    #include /usr/local/nginx/conf/pagespeed.conf;
    #include /usr/local/nginx/conf/pagespeedhandler.conf;
    
    # limit_conn limit_per_ip 16;
    # ssi on;
    
    location / {
    # block common exploits, sql injections etc
    include /usr/local/nginx/conf/block.conf;
    
    #Enables directory listings when index file not found
    #autoindex on;
    }
    
    location / {
    include /usr/local/nginx/conf/wpsecure.conf;
    include /usr/local/nginx/conf/wpcache.conf;
    include /usr/local/nginx/conf/phpwpcache.conf;
    
    try_files $uri $uri/ /index.php?q=$request_uri;
    }
    
    # example nginx-http-concat
    # /csstest/??one.css,two.css
    #location /csstest {
    #concat on;
    #concat_max_files 20;
    #}
    
    include /usr/local/nginx/conf/staticfiles.conf;
    include /usr/local/nginx/conf/php.conf;
    #include /usr/local/nginx/conf/phpstatus.conf;
    include /usr/local/nginx/conf/drop.conf;
    #include /usr/local/nginx/conf/errorpage.conf;
    
    }
    
    
    

    please let me know my final vHOST is okay
    ?
     
  10. Yohan

    Yohan Member

    68
    3
    8
    Sep 24, 2015
    Ratings:
    +4
    Local Time:
    2:16 AM
    1.9.x
    MariaDB 10
    Even if i add this link in to /usr/local/nginx/conf/nginx.conf

    Code:
    http {
    include /usr/local/nginx/conf/wp_fastcgicache.conf;
    
    Code:
    fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=WPCACHE:16m max_size=32m 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" nocache:$no_cache '
                      '$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;
    }
    
    
    

    nginx won''t restart
     
  11. eva2000

    eva2000 Administrator Staff Member

    34,638
    7,656
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +11,774
    Local Time:
    6:46 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    does /var/cache/nginx exist ?
     
  12. Yohan

    Yohan Member

    68
    3
    8
    Sep 24, 2015
    Ratings:
    +4
    Local Time:
    2:16 AM
    1.9.x
    MariaDB 10
  13. eva2000

    eva2000 Administrator Staff Member

    34,638
    7,656
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +11,774
    Local Time:
    6:46 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    then check your nginx error logs as per faq item 19
     
  14. Yohan

    Yohan Member

    68
    3
    8
    Sep 24, 2015
    Ratings:
    +4
    Local Time:
    2:16 AM
    1.9.x
    MariaDB 10
    Code:
    2015/10/02 10:00:25 [emerg] 23172#23172: unknown "no_cache" variable
    2015/10/02 10:01:30 [emerg] 23250#23250: unknown "no_cache" variable
    2015/10/02 10:14:54 [alert] 23299#23299: *1379 open socket #34 left in connection 4
    2015/10/02 10:14:54 [alert] 23299#23299: *1378 open socket #33 left in connection 7
    2015/10/02 10:14:54 [alert] 23299#23299: aborting
    2015/10/02 10:14:54 [alert] 23301#23301: *1377 open socket #33 left in connection 5
    2015/10/02 10:14:54 [alert] 23301#23301: *1376 open socket #32 left in connection 7
    2015/10/02 10:14:54 [alert] 23301#23301: aborting
    2015/10/02 10:14:54 [emerg] 23564#23564: unknown "no_cache" variable
    2015/10/02 10:15:03 [emerg] 23612#23612: unknown "no_cache" variable
    
     
  15. eva2000

    eva2000 Administrator Staff Member

    34,638
    7,656
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +11,774
    Local Time:
    6:46 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    from instructions
     
  16. Yohan

    Yohan Member

    68
    3
    8
    Sep 24, 2015
    Ratings:
    +4
    Local Time:
    2:16 AM
    1.9.x
    MariaDB 10
    Its working !!
    my Vhost now like this


    Code:
    # Centmin Mod Getting Started Guide
    # must read http://centminmod.com/getstarted.html
    
    # redirect from non-www to www
    # uncomment, save file and restart Nginx to enable
    # if unsure use return 302 before using return 301
    #server {
    #  listen  80;
    #  server_name mydomain.info;
    #  return 301 $scheme://www.mydomain.info$request_uri;
    #  }
    
    server {
      server_name mydomain.info www.mydomain.info;
    
    # 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;
    
      # limit_conn limit_per_ip 16;
      # ssi  on;
    
      access_log /home/nginx/domains/mydomain.info/log/access.log combined buffer=256k flush=60m;
      error_log /home/nginx/domains/mydomain.info/log/error.log;
    
      root /home/nginx/domains/mydomain.info/public;
    
      # prevent access to ./directories and files
      location ~ (?:^|/)\. {
      deny all;
      }
    
    #include /usr/local/nginx/conf/wpsupercache_mydomain.info.conf;
    
      location / {
      # 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;
    # Wordpress Permalinks
    try_files $uri $uri/ /index.php?q=$uri&$args;
    
      }
    
    location ~* /(wp-login\.php) {
      limit_req zone=xwplogin burst=1 nodelay;
      #limit_conn xwpconlimit 30;
      auth_basic "Private";
      auth_basic_user_file /home/nginx/domains/mydomain.info/htpasswd_wplogin;
      include /usr/local/nginx/conf/php-wpsc.conf;
    }
    
    location ~* /(xmlrpc\.php) {
      limit_req zone=xwplogin burst=2 nodelay;
      #limit_conn xwpconlimit 30;
      include /usr/local/nginx/conf/php-wpsc.conf;
    }
    include /usr/local/nginx/conf/wpsecure.conf;
    include /usr/local/nginx/conf/wpcache.conf;
      include /usr/local/nginx/conf/wpsecure_mydomain.info.conf;
      include /usr/local/nginx/conf/php-wpsc.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;
    }
     
  17. Yohan

    Yohan Member

    68
    3
    8
    Sep 24, 2015
    Ratings:
    +4
    Local Time:
    2:16 AM
    1.9.x
    MariaDB 10
    'Hmmm i dont know if it work
    Code:
    [[email protected] ~]# curl -I http://mydomain.info
    HTTP/1.1 200 OK
    Date: Fri, 02 Oct 2015 11:10:51 GMT
    Content-Type: text/html; charset=UTF-8
    Connection: keep-alive
    Vary: Accept-Encoding
    X-CF-Powered-By: WP 1.3.18
    X-Pingback: http://mydomain.info/xmlrpc.php
    Server: nginx centminmod
    
     
  18. eva2000

    eva2000 Administrator Staff Member

    34,638
    7,656
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +11,774
    Local Time:
    6:46 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    you still have old wordpress super cache php include files instances in your vhost instead of /usr/local/nginx/conf/phpwpcache.conf
    Code:
    include /usr/local/nginx/conf/php-wpsc.conf;
     
  19. Yohan

    Yohan Member

    68
    3
    8
    Sep 24, 2015
    Ratings:
    +4
    Local Time:
    2:16 AM
    1.9.x
    MariaDB 10
    Can you please make me out put of VHOST ? correct one ? sorry i bit cnfused with this all codes .... simply modify my above VHOS and past with correct one ?
     
  20. Cr0w

    Cr0w Member

    165
    9
    18
    Mar 17, 2015
    Iran
    Ratings:
    +13
    Local Time:
    1:16 AM
    1.9.x
    5.5
    /var/cache/nginx does't exist on my server

    and i have this problem too :(
     
..