Join the community today
Register Now

WP Rocket installation on Nginx

Discussion in 'Blogs & CMS usage' started by Mrbo, Feb 25, 2019.

  1. Mrbo

    Mrbo Member

    109
    7
    18
    Jun 17, 2018
    Ratings:
    +7
    Local Time:
    12:44 PM
  2. eva2000

    eva2000 Administrator Staff Member

    41,064
    9,174
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +14,078
    Local Time:
    3:44 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    I believe a few folks here on this forum us WP Rocket, you can try searching the forums

    FYI, Centmin Mod installs Nginx in /usr/local/nginx instead of /etc/nginx
     
    • Like Like x 1
  3. Mrbo

    Mrbo Member

    109
    7
    18
    Jun 17, 2018
    Ratings:
    +7
    Local Time:
    12:44 PM
    I tried to search for wp rocket on the forum but nobody seems to have tried to implement the modification recommended by wp rocket for nginx servers. Its recommended by them since wp-rocket doesnt write to the .htaccess file on nginx.

    I managed to install the modification now. I just have one more question before I can test it and see if it made any performance improvements. Which file do they refer to to modify in the centminmod stack?


    Ps: Do I need to make any additional change if I installed wordpress through cmm menu option 22 with wp super cache? Saw that you recommended some changes on this old thread.
     
    Last edited: Feb 25, 2019
  4. eva2000

    eva2000 Administrator Staff Member

    41,064
    9,174
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +14,078
    Local Time:
    3:44 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    that's your nginx site/domain vhost config files https://centminmod.com/configfiles.html

     
  5. fabianski

    fabianski Member

    99
    12
    8
    Feb 20, 2019
    Brazil
    Ratings:
    +31
    Local Time:
    2:44 AM
    Hi,
    Did you get set up?
    Here is the cache working, but I can not access any page other than the initial one I receive error 404.
    I think this happens because of the permanent links of wordpress ...
     
  6. fabianski

    fabianski Member

    99
    12
    8
    Feb 20, 2019
    Brazil
    Ratings:
    +31
    Local Time:
    2:44 AM
    @eva2000 can you help me solve this problem with permanent links?
    I used the wordpress installation through menu option 22 and chose the enabler cache, then removed using this tutorial:

    Wordpress - Disable Or Remove KeyCDN Cache Enabler

    For the configuration of wp rocket with nginx I used this one:
    maximejobin/rocket-nginx

    I think this could also be because of the default nginx folder ... Since the plugin configuration uses the folder /etc/nginx instead of /usr/local/nginx

    I used the following commands
    cd /usr/local/nginx
    git clone maximejobin/rocket-nginx
    cd rocket-nginx
    cp rocket-nginx.ini.disabled rocket-nginx.ini
    php rocket-parser.php

    thanks in advance
     
  7. Mrbo

    Mrbo Member

    109
    7
    18
    Jun 17, 2018
    Ratings:
    +7
    Local Time:
    12:44 PM
    You need to add this,
    include /usr/local/nginx/rocket-nginx/default.conf; ,to your vhost file which is located at /usr/local/nginx/conf/conf.d/ . And then you need to comment cache enabler, wp-supercache or redis, comment out wordpress permalinks and change all instances of php-wpsc to just php. This is how my vhost file look like.

    Code:
    #x# HTTPS-DEFAULT
     server {
      
       server_name mywebsite.com www.mywebsite.com;
       return 302 https://mywebsite.com$request_uri;
       include /usr/local/nginx/conf/staticfiles.conf;
     }
    
    server {
      listen 443 ssl http2;
      server_name mywebsite.com www.mywebsite.com;
    
      include /usr/local/nginx/conf/ssl/mywebsite.com/mywebsite.com.crt.key.conf;
      include /usr/local/nginx/conf/ssl_include.conf;
    
      # cloudflare authenticated origin pull cert community.centminmod.com/threads/13847/
      ssl_client_certificate /usr/local/nginx/conf/ssl/cloudflare/mywebsite.com/origin.crt;
      ssl_verify_client on;
      http2_max_field_size 16k;
      http2_max_header_size 32k;
      # mozilla recommended
      ssl_ciphers TLS13-AES-128-GCM-SHA256:TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305: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";
      #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/mywebsite.com/log/access.log combined buffer=256k flush=5m;
      error_log /home/nginx/domains/mywebsite.com/log/error.log;
    
      include /usr/local/nginx/conf/autoprotect/mywebsite.com/autoprotect-mywebsite.com.conf;
      root /home/nginx/domains/mywebsite.com/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/rocket-nginx/default.conf;
      #include /usr/local/nginx/conf/wpincludes/mywebsite.com/wpcacheenabler_mywebsite.com.conf;
      #include /usr/local/nginx/conf/wpincludes/mywebsite.com/wpsupercache_mywebsite.com.conf;
      # https://community.centminmod.com/posts/18828/
      #include /usr/local/nginx/conf/wpincludes/mywebsite.com/rediscache_mywebsite.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;
    
      }
    
    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/mywebsite.com/htpasswd_wplogin;   
        include /usr/local/nginx/conf/php.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.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.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.conf;
        
        # https://community.centminmod.com/posts/18828/
        #include /usr/local/nginx/conf/php-rediscache.conf;
    }
    
      include /usr/local/nginx/conf/wpincludes/mywebsite.com/wpsecure_mywebsite.com.conf;
      include /usr/local/nginx/conf/php.conf;
     
      # https://community.centminmod.com/posts/18828/
      #include /usr/local/nginx/conf/php-rediscache.conf;
      include /usr/local/nginx/conf/pre-staticfiles-local-mywebsite.com.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;
    }
    
     
    • Like Like x 3
  8. fabianski

    fabianski Member

    99
    12
    8
    Feb 20, 2019
    Brazil
    Ratings:
    +31
    Local Time:
    2:44 AM
    I did this but I still get a 404 error when accessing any page except the home page
    I already tried to update the permanent links in the wordpress panel but without success.
     
  9. mrkip

    mrkip New Member

    7
    4
    3
    Jan 29, 2019
    Ratings:
    +4
    Local Time:
    6:44 AM
    Mrbo instructions worked for me. Cheers
    @fabianski Are you sure you changed all the php-wpsc to php. Make sure you do a search for them in nano using Ctrl+W. There are quite a few instances of them in the the nginx config file.
    Also, double check that the permalinks directive is commented out in nginx file. I had the same problem until i commented the following line
    Code:
    # Wordpress Permalinks
     # try_files $uri $uri/ /index.php?q=$uri&$args;
    to
    Code:
    # Wordpress Permalinks
      try_files $uri $uri/ /index.php?q=$uri&$args;
     
    • Like Like x 1
  10. fabianski

    fabianski Member

    99
    12
    8
    Feb 20, 2019
    Brazil
    Ratings:
    +31
    Local Time:
    2:44 AM
    Code:
    try_files $uri $uri/ /index.php?q=$uri&$args;
    Using this setting for permanent links creates the cache file in a wrong folder

    It ends up getting inside a subfolder and nginx will not serve it since it is looking in another folder ...

    Code:
    Wrong folder
    
    /home/nginx/domains/domain.com/public/wp-content/cache/wp-rocket/domain.com/blog/post/_q=%2fpost%2f/file.html
    To solve, we have to change to this

    Code:
    try_files $uri $uri/ /index.php?$args;
    It will no longer create a subfolder and will serve the cache file correctly

    Code:
    Correct folder
    /home/nginx/domains/domain.com/public/wp-content/cache/wp-rocket/domain.com/blog/post/_q=%2fpost%2f/file.html
    To see these details it is necessary to activate the debug mode in the file rocket-nginx.ini

    Code:
    debug = true
    Another thing I was in trouble with was the headers, to solve this it is necessary to put the ones you use in the file rocket-nginx.ini

    Code:
    ; HTTP(S) headers
    ; ...
    http_header[X-Frame-Options]="SAMEORIGIN"
    http_header[X-XSS-Protection]="1; mode=block"
    http_header[X-Content-Type-Options]="nosniff"
    
    ; HSTS header value
    ; ...
    header_hsts = "max-age=31536000"


    Then just update the configuration file again and restart nginx

    Code:
    php rocket-nginx.ini
    php rocket-parser.php
    service nginx restart
    I think with this my doubts with wp rocket are over:D
     
    • Like Like x 2
    • Informative Informative x 1
  11. eva2000

    eva2000 Administrator Staff Member

    41,064
    9,174
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +14,078
    Local Time:
    3:44 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    nice @fabianski and @Mrbo thanks for sharing your workarounds, i am sure other wp rocket users will appreciate this :) (y)
     
  12. BamaStangGuy

    BamaStangGuy Active Member

    575
    171
    43
    May 25, 2014
    Ratings:
    +232
    Local Time:
    12:44 AM
    I love me some WP Rocket.
     
  13. EckyBrazzz

    EckyBrazzz Active Member

    520
    110
    43
    Mar 28, 2018
    >>>>Click here<<<< i'm nearby......
    Ratings:
    +201
    Local Time:
    2:44 AM
    1.17.x
    10.3.x
    Yep Wp Rocket... My idea of today. Got a specail offer with a discount of 25% for the infinify one. Spent $186.75 and followed the steps above.

    Loved it at first but a better look and all WebP, the WepP Express that worked before, it's simply gone.

    Placed a backup and on each step verified the existens of our WebP images, well they disapear at the moment that you install WP Rocket.

    No more WebP images on my page.

    They want you to install imagify to get support for WebP, but we have our whitelisted WebPExpress.
    I installed it, the plugin imagify and disabled all options except to display WebP images, but nothing seems to work. Got the API key and some credits. (hmm, 25MB/month free to optimize) --> WebPExpress does it for free.
    Project_CMM_7271.png

    @eva2000 I need some help here, it's a little unfair of WP-Rocket. I disabled the autoproction in the conf.ssl, the wpinclude but on CMM it is a no go.

    But sadly as I was when I checked webpagetest.org. Our beautiful WebPExpress is with WP Rocket a no go.

    Project_CMM_7270.png
     
  14. eva2000

    eva2000 Administrator Staff Member

    41,064
    9,174
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +14,078
    Local Time:
    3:44 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    probably WP-Nginx nginx rules are overriding Centmin Mod's default WebP conditional serving code Nginx Serving WebP Images Conditionally Demo or their WebP images aren't named in format original.png.webp or original.jpg.webp
     
  15. EckyBrazzz

    EckyBrazzz Active Member

    520
    110
    43
    Mar 28, 2018
    >>>>Click here<<<< i'm nearby......
    Ratings:
    +201
    Local Time:
    2:44 AM
    1.17.x
    10.3.x
    How to resolve it? Only a complete removal of the plugin will work.
     
  16. EckyBrazzz

    EckyBrazzz Active Member

    520
    110
    43
    Mar 28, 2018
    >>>>Click here<<<< i'm nearby......
    Ratings:
    +201
    Local Time:
    2:44 AM
    1.17.x
    10.3.x
    imagify plugins converts the ericson igmage the same way as the WebPExpress

    Code (Text):
    -rw-r--r-- 1 nginx nginx 8.1K Jul  9 10:23 80px-Expert.jpg
    -rw-r--r-- 1 nginx nginx 3.4K Jul  9 10:23 80px-Expert.jpg.webp
    -rw-r--r-- 1 nginx nginx  48K Jul 11 05:04 ericson-1180x355.png
    -rw-r--r-- 1 nginx nginx 5.4K Jul 11 05:04 ericson-1180x355.png.webp
    -rw-r--r-- 1 nginx nginx  12K Jul 11 05:04 ericson-146x146.png
    -rw-r--r-- 1 nginx nginx 3.5K Jul 11 05:04 ericson-146x146.png.webp
    -rw-r--r-- 1 nginx nginx  12K Jul 11 05:04 ericson-150x150.png
    -rw-r--r-- 1 nginx nginx 3.6K Jul 11 05:04 ericson-150x150.png.webp
    -rw-r--r-- 1 nginx nginx  15K Jul 11 05:04 ericson-237x175.png
    -rw-r--r-- 1 nginx nginx 4.4K Jul 11 05:04 ericson-237x175.png.webp
    -rw-r--r-- 1 nginx nginx  50K Jul 11 05:04 ericson-676x390.png
    -rw-r--r-- 1 nginx nginx 7.6K Jul 11 05:04 ericson-676x390.png.webp
    -rw-r--r-- 1 nginx nginx 5.5K Jul 11 05:04 ericson-80x80.png
    -rw-r--r-- 1 nginx nginx 1.8K Jul 11 05:04 ericson-80x80.png.webp
    -rw-r--r-- 1 nginx nginx 3.3K Jul 11 05:04 ericson.png
    -rw-r--r-- 1 nginx nginx 4.0K Jul 11 05:04 ericson.png.webp
    
     
  17. EckyBrazzz

    EckyBrazzz Active Member

    520
    110
    43
    Mar 28, 2018
    >>>>Click here<<<< i'm nearby......
    Ratings:
    +201
    Local Time:
    2:44 AM
    1.17.x
    10.3.x
    Not a singel PNG or JPG image shows up. On the red arrow should be the erison logo Project_CMM_7272.png
     
  18. eva2000

    eva2000 Administrator Staff Member

    41,064
    9,174
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +14,078
    Local Time:
    3:44 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    no idea as I don't use or have ever used WP-Rocket - seems the urls they serve from are image.jpg.webp though from your browser network tab screenshots which is probably why
     
  19. fabianski

    fabianski Member

    99
    12
    8
    Feb 20, 2019
    Brazil
    Ratings:
    +31
    Local Time:
    2:44 AM
  20. EckyBrazzz

    EckyBrazzz Active Member

    520
    110
    43
    Mar 28, 2018
    >>>>Click here<<<< i'm nearby......
    Ratings:
    +201
    Local Time:
    2:44 AM
    1.17.x
    10.3.x
    @fabianski Obrigado! I know that I should work, I was reading a lot about it and there are many people that have wp-rocket working with different plugins what produce WebP images. That's why I bought with full faith the infinity version because it should work.

    I also used your tip about the warm-cache.(y)

    I followed the instructions by the letter, even compared the wp.conf and wp-wpsc.conf, but the diff only showed 1 difference. Now, at the moment that I install wp-rocket, WebP stops working.

    Question/request: Can you please post on a private gist or for you any for convenience place your plugins, settings, config files (please remove any domains' etc) and send me a message(conversation) with the links. It would help me a lot to solve this problem.
     
  21. fabianski

    fabianski Member

    99
    12
    8
    Feb 20, 2019
    Brazil
    Ratings:
    +31
    Local Time:
    2:44 AM
    Well, I use wp-rocket only for caching, other functions of it like minification I leave disabled.

    The webpexpress is set up as eva explained in the tutorial.

    The only difference is in this part:

    I added this rule to the file /nginx/conf/conf.d/mydomain.org.ssl.conf rather than /nginx/conf/wpincludes/mydomain.org.ssl.conf

    My nginx settings are here: View Paste T89ke
     
    • Like Like x 2
    • Informative Informative x 1