Join the community today
Register Now

Wordpress NGINX will not restart if I enable wpcache.conf

Discussion in 'Blogs & CMS usage' started by DaB, Oct 6, 2020.

  1. DaB

    DaB Member

    32
    3
    8
    Aug 10, 2016
    Ratings:
    +4
    Local Time:
    12:59 PM
    Current
    Current
    I am trying to enable the FAST CGI caching, I have been working through the guides.

    If I uncomment

    # include /usr/local/nginx/conf/wpcache.conf; then NGINX will not restart.

    wpcache.conf file

    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 ~* "/\?add-to-cart=|cart/|my-account/|checkout/|shop/checkout/|store/checkout/|customer-dashboard/|addons/|(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|edd_items_in_cart|woocommerce_items_in_cart|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;
        } 


    This is my domain conf file.....


    Code:
    #x# HTTPS-DEFAULT
     server {
      
       server_name my.domain www.my.domain;
       return 302 https://my.domain$request_uri;
       include /usr/local/nginx/conf/staticfiles.conf;
     }
    
    server {
      listen 443 ssl http2 reuseport;
      server_name my.domain www.my.domain;
    
      include /usr/local/nginx/conf/ssl/my.domain/my.domain.crt.key.conf;
      include /usr/local/nginx/conf/ssl_include.conf;
    
    location ~* \.(js|css|png|jpg|jpeg|gif|svg|ico|webp)$ {
    expires 365d;
     
     add_header Cache-Control "public, no-transform";
    }
    
    
      # cloudflare authenticated origin pull cert community.centminmod.com/threads/13847/
      #ssl_client_certificate /usr/local/nginx/conf/ssl/cloudflare/my.domain/origin.crt;
      #ssl_verify_client on;
      http2_max_field_size 16k;
      http2_max_header_size 32k;
      http2_max_requests 50000;
      # mozilla recommended
      ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS;
      ssl_prefer_server_ciphers   on;
      #add_header Alternate-Protocol  443:npn-spdy/3;
    
      # before enabling HSTS line below read centminmod.com/nginx_domain_dns_setup.html#hsts
      #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;
      #add_header Referrer-Policy "strict-origin-when-cross-origin";
      #add_header Feature-Policy "accelerometer 'none'; camera 'none'; geolocation 'none'; gyroscope 'none'; magnetometer 'none'; microphone 'none'; payment 'none'; usb 'none'";
      #spdy_headers_comp 5;
      ssl_buffer_size 1369;
      ssl_session_tickets on;
     
      # enable ocsp stapling
      resolver 8.8.8.8 8.8.4.4 1.1.1.1 1.0.0.1 valid=10m;
      resolver_timeout 10s;
      ssl_stapling on;
      ssl_stapling_verify on;
    
    # 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/my.domain/log/access.log combined buffer=256k flush=5m;
      error_log /home/nginx/domains/my.domain/log/error.log;
    
      include /usr/local/nginx/conf/autoprotect/my.domain/autoprotect-my.domain.conf;
      root /home/nginx/domains/my.domain/public;
      # 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;
    
      #include /usr/local/nginx/conf/wpincludes/my.domain/wpcacheenabler_my.domain.conf;
      include /usr/local/nginx/conf/wpincludes/my.domain/wpsupercache_my.domain.conf;
      # https://community.centminmod.com/posts/18828/
      include /usr/local/nginx/conf/wpincludes/my.domain/rediscache_my.domain.conf; 
    
      location / {
      include /usr/local/nginx/conf/503include-only.conf;
      # include /usr/local/nginx/conf/wpcache.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_webp $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;
    
      }
    
    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/my.domain/htpasswd_wplogin;   
        include /usr/local/nginx/conf/php-wpsc.conf;
        
        # https://community.centminmod.com/posts/18828/
        #include /usr/local/nginx/conf/php-rediscache.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;
    }
    
    location ~* /wp-admin/(load-scripts\.php) {
        limit_req zone=xwprpc burst=5 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;
    }
    
    location ~* /wp-admin/(load-styles\.php) {
        limit_req zone=xwprpc burst=5 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;
    }
    
    location ~* \.(xml)$ { expires -1; }
    location /robots.txt { expires -1; }
    
    # SEO Sitemaps
    rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.xml$ "/index.php?xml_sitemap=params=$2" last;
    rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.xml\.gz$ "/index.php?xml_sitemap=params=$2;zip=true" last;
    rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.html$ "/index.php?xml_sitemap=params=$2;html=true" last;
    rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.html.gz$ "/index.php?xml_sitemap=params=$2;html=true;zip=true" last;
        
      include /usr/local/nginx/conf/wpincludes/my.domain/wpsecure_my.domain.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/pre-staticfiles-local-my.domain.conf;
      include /usr/local/nginx/conf/pre-staticfiles-global.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/wpsecure.conf;
     
    }
    
     
  2. eva2000

    eva2000 Administrator Staff Member

    45,441
    10,312
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,994
    Local Time:
    10:59 PM
    Nginx 1.19.x
    MariaDB 5.5/10.x
  3. DaB

    DaB Member

    32
    3
    8
    Aug 10, 2016
    Ratings:
    +4
    Local Time:
    12:59 PM
    Current
    Current
    Is that guide how your forum is WordPress installation is set up, plugins and all?
     
  4. eva2000

    eva2000 Administrator Staff Member

    45,441
    10,312
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,994
    Local Time:
    10:59 PM
    Nginx 1.19.x
    MariaDB 5.5/10.x
    My forums or you mean Wordpress? 99% of my Wordpress sites use Cache Enabler config. Only one uses fastcgi_cache PHP-FPM config as I am testing it and evaluating it for inclusion in centmin.sh menu option 22 and that site is my servermanager.guide site. Cache Enabler config via centmin.sh menu option 22 will still be faster than future fastcgi_cache PHP-FPM config in centmin.sh menu option 22 as Cache Enabler cached files can be pre-compressed via gzip via my Autoptimize Gzip plugin which is auto installed with centmin.sh menu option 22 Wordpress installs and allows Nginx to serve cached files that are pre-compressed for smaller file sizes and better latency than on the fly compressed fastcgi_cache PHP-FPM cached file
     
  5. DaB

    DaB Member

    32
    3
    8
    Aug 10, 2016
    Ratings:
    +4
    Local Time:
    12:59 PM
    Current
    Current
    I meant Wordpress sorry.

    I use WP Rocket as it stands but I would switch based on your suggestions. Thank you.