• Hi,

    I have been using Apache2 with WordPress on a Micro EC2 instance for one year. Today I made the move to switch to Nginx since it is mean to be less resource hungry than Apache2.

    The first objective impression is very good. It feels nice.

    However my W3 Total Cache: Google Page Speed Report: has now gone down from 87 to 57. I get now two red points I didnt have before:

    Leverage browser caching (it is enabled, I dont understand why)
    Enable compression

    Everything is enabled as before incl. APC etc. The only thing that I couldn’t get working under nginx was minify. Which is now disabled.

    Could this be related? Please help, otherwise I am not sure if the move to nginx was a good one.

    thanks,

Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter houmie

    (@houmie)

    Btw, I have managed to get minify working as well. Everything is now like it was with Apache. Why do I get those two red errors:

    Leverage browser caching
    Enable compression

    No difference in scroe. Still 57.

    The reason you’re having issues is because Apache rewrites and other directives used by W3TC do not apply in Nginx. Therefore, you will have to manually edit the Nginx vhost.

    For WordPress, you’re going to want to use the following in server {}:

    if ($host ~* ^www\.(.*)) {
        set $host_without_www $1;
        rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
    }
    if (!-e $request_filename) {
        rewrite ^(.+)$ /index.php?q=$1 last;
    }
    location ~* \.(js|css|png|jpg|jpeg|gif|ico)(\?ver=[0-9.]+)?$ {
        expires 1y;
    }

    Also, for PHP, I strongly suggest using PHP-FPM over FastCGI. Under heavy loads, FastCGI daemon will crash repeatedly, while FPM will take a beating ??

    Heavy loads tested = 500 concurrent connections, 100k requests.

    You can use this configuration: https://rtcamp.com/tutorials/wordpress-nginx-w3-total-cache/

    It will handle expiry header to improve browser-caching, minification and more.

    Thread Starter houmie

    (@houmie)

    @rahul286

    Thank you for your excellent blog. I have read it before and it was helpful getting nginx working so far. I was reading five other tutorials before I had found yours, and they all failed on me. ?? I am not sure if editing the vhost manually is really necessary where W3C does exactly that for you. Please carry on reading and I explain it later.

    @andreiguru

    Thank you for the help. I am in fact using PHP-FPM ??

    This my setting:

    location ~ \.php$ {
                   # With php5-fpm:
                   fastcgi_pass unix:/var/run/php5-fpm.sock;
                   fastcgi_index index.php;
                   include fastcgi_params;
            }

    Regarding editing manually the vhost, I am not sure if that is necessary. Please continue reading the post.

    Today I tested the analysis again and it jumped up to 76 points.

    The “Enable Compression” is completely gone.
    “Leverage browser caching” is now yellow instead of red.

    It says now:

    The following cacheable resources have a short freshness lifetime. Specify an expiration at least one week in the future for the following resources:

    Correct me if I am wrong, it seems the header expiry are set but are a bit fresh. So in a week’s time, this should become “old” enough and hence score higher?

    Now to your setting suggestions. I think the only manual step is to include the nginx.conf that W3C is creating for you in the vhost.

    include /var/www/example/htdocs/nginx.conf;

    It seems W3C has already generated all settings in there that you have both suggested in the external conf file:

    # BEGIN W3TC Browser Cache
    gzip on;
    gzip_types text/css application/x-javascript text/x-component text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
    location ~ \.(css|js|htc)$ {
        expires 31536000s;
        add_header Pragma "public";
        add_header Cache-Control "public, must-revalidate, proxy-revalidate";
        add_header X-Powered-By "W3 Total Cache/0.9.2.4";
    }
    location ~ \.(html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml)$ {
        expires 3600s;
        add_header Pragma "public";
        add_header Cache-Control "public, must-revalidate, proxy-revalidate";
        add_header X-Powered-By "W3 Total Cache/0.9.2.4";
    }
    location ~ \.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$ {
        expires 31536000s;
        add_header Pragma "public";
        add_header Cache-Control "public, must-revalidate, proxy-revalidate";
        add_header X-Powered-By "W3 Total Cache/0.9.2.4";
    }
    # END W3TC Browser Cache
    # BEGIN W3TC Minify core
    rewrite ^/wp-content/w3tc/min/w3tc_rewrite_test$ /wp-content/w3tc/min/index.php?w3tc_rewrite_test=1 last;
    rewrite ^/wp-content/w3tc/min/(.+\.(css|js))$ /wp-content/w3tc/min/index.php?file=$1 last;
    # END W3TC Minify core

    Do you think it is missing anything there? Because I think its best to drive the settings from one place. Otherwise the manual settings could get in the way of W3C settings. Don’t you think?

    So I have a few question for you gurus ??

    1) How do I combine images into CSS sprites? (Another yellow)
    2) If I go to https://www.chasebot.com (secured connection) it is all garbled. Is that because of minify? because over http it is just fine. https://www.chasebot.com
    3) Now that you know my settings, is there any other setting missing you would recommend?

    Many Thanks for your time,

    In my tutorials you no need to include nginx conf file generated by W3 Total Cache. I handled them all (Just in less lines and better way)

    On other note, anytime you OR a plugin make changes to any of nginx conf file, you need to reload nginx config. Nginx doesn’t have .htaccess style support.
    Today only I started a discussion on nginx forum – https://forum.nginx.org/read.php?2,232176,232199#msg-232199 (planning to add auto-reload support for nginx-helper with easyengine)

    For CSS Sprites, there is no shortcut. Sorry to say but you have to do it yourself or find an expert web-developer/designer.

    Thread Starter houmie

    (@houmie)

    Thanks Rahul, I found a website that creates CSS sprites.

    I will check out that discussion you have started. No problem with reloading the nginx config manually.

    One last thing, there is no fault currently in my settings regarding expiry headers, correct? So is my assumption correct that I have to simply wait a bit longer until my score goes up? Or is there something else I am missing in that area?

    Many Thanks,

    If config is correct, you should be able to see updated results instantly. Try this service – https://gtmetrix.com/

    In other case, extra config in file form which you are including /var/www/example/htdocs/nginx.conf; may create a conflict with content of nginx.conf.

    If possible paste full config…

    Thread Starter houmie

    (@houmie)

    Thanks Rahul,

    The content of /var/www/example/htdocs/nginx.conf was already in full above.

    And this is the vhost:

    depricated

    and this is /etc/nginx/nginx.conf

    depricated
    Many thanks for your advice,

    All looks good in above config! Only way to find out us debugging nginx

    All I can say, is to try again my tutorial. I guess it worked for you.
    Any reason not to use it?

    Thread Starter houmie

    (@houmie)

    Thanks I will try that and see. ??

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘[W3 Total Cache] – Nginx looses 30 Google page score’ is closed to new replies.