GZip & Browser Cache fro new WP Sites

Hey there,

I´ve noted that all newly-installed WP sites on LocalWP on my Mac, have both GZip and Browser Cache disabled. My speed plugin (Hummingbird from WPMU DEV) cannot detect them.

I´ve checked the .conf files and everything seems to be in place. Please let me know if there is any way to make them to be enabled/recognized by my system.

Thank you very much and best regards!

Hey @fabiofava! To clarify did you add Hummingbird’s NGINX configuration to your .conf and then restart your site to recompile the changes and it’s still not working?

I just wanted to align on what you’ve tested so far to try and replicate. Thanks!

Hey @Nick-B thanks for getting back!

I’ve tried adding Hummingbird codes for GZip & Browser Cache (then shut down all sites and close and re-open LocalWP), but all I go was 502 errors instead of sites loading. I have no idea about recompiling, sorry for my low-tech-level.

I’ve checked the .conf files for LocalWP, and the Includes have all the GZip info seems to be there (can’t say about Browser Cache as I’m very low-level on coding and NGinx). Adding codes to LocalWP’s conf files, equals 502.

I know it’s not super important on Local Development Environments, but I’d like to better understand how LocalWP works and how to have the option to enable it all, so to better test how things can be pre-set to when I move to Live.

Thank you so much for all your patience and help, brother.

All my best wishes, always, cheers!

As long as you’re hitting Stop and then Start in the Local app on your site(s) @fabiofava that will effectively recompile your changes. It acts like a “refresh”.

Curiously, I just installed and activated the free Hummingbird plugin on a test site in my Local app but it’s telling me it’s good to go. Is there something else I can do on my end to test and replicate what you’re seeing? I’m not overly familiar with this plugin.

Hey @Nick-B thanks for getting back!

That’s very weird. On my Mac running Monterey 12.7.6 it always installs WP without GZip and Browser Cache. Both single site and multisite. On the site I’ve cloned from a Live site, it works fine. So I assume it’s something WP-related, not NGinx server-related… Any light on what could be causing it?

Cheers!

What about if you create a new, blank site in Local and install Hummingbird there? What happens?

Hey @Nick-B thanks for getting back!

That’s what I’ve tried. Both Single WP Sites and Multisites get GZip working but not Browser Cache. On my imported site none of them work.

Cheers!

I tried some different NGINX configs and I could replicate the 502s but eventually found something that works here @fabiofava

Here is my config on just a new Local site I spun up to test:

upstream php {
  {{#each fastcgi_servers}}
  server {{this}};
  {{/each}}
}

server {
    listen 127.0.0.1:{{port}};
    listen [::1]:{{port}};
    root   "{{root}}";

    index index.php index.html index.htm;

    #
    # Generic restrictions for things like PHP files in uploads
    #
    include includes/restrictions.conf;

    #
    # Gzip rules
    #
    include includes/gzip.conf;

    #
    # WordPress Rules
    #
    {{#unless site.multiSite}}
    include includes/wordpress-single.conf;
    {{else}}
    include includes/wordpress-multi.conf;
    {{/unless}}

    #
    # Forward 404's to WordPress
    #
    error_page 404 = @wperror;
    location @wperror {
        rewrite ^/(.*)$ /index.php?q=$1 last;
    }

    #
    # Static file rules
    #
  #
# Static file caching rules
#

location ~* \.(?:txt|xml|js)$ {
    access_log off;
    log_not_found off;
    expires 1y;
    add_header Cache-Control "public, max-age=31536000, immutable";
}

location ~* \.(?:css)$ {
    access_log off;
    log_not_found off;
    expires 1y;
    add_header Cache-Control "public, max-age=31536000, immutable";
}

location ~* \.(?:flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav|mp4|m4v|ogg|webm|aac|eot|ttf|otf|woff|woff2|svg)$ {
    access_log off;
    log_not_found off;
    expires 1y;
    add_header Cache-Control "public, max-age=31536000, immutable";
    add_header Access-Control-Allow-Origin *;
}

location ~* \.(?:jpg|jpeg|png|gif|swf|webp)$ {
    access_log off;
    log_not_found off;
    expires 1y;
    add_header Cache-Control "public, max-age=31536000, immutable";
}

    #
    # PHP-FPM
    #
    location ~ \.php$ {
        try_files $uri =404;

        fastcgi_split_path_info ^(.+\.php)(/.+)$;

        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_FILENAME         $document_root$fastcgi_script_name;
        fastcgi_param   SCRIPT_NAME             $fastcgi_script_name;
        fastcgi_param   PATH_INFO               $fastcgi_path_info;
        fastcgi_param   PATH_TRANSLATED         $document_root$fastcgi_path_info;
        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   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             $host;

        fastcgi_param   HTTPS                   $fastcgi_https;

        fastcgi_param   REDIRECT_STATUS         200;

        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

        fastcgi_pass php;
        fastcgi_buffer_size      64k;
        fastcgi_buffers          32 32k;
        fastcgi_read_timeout     1200s;

        proxy_buffer_size        64k;
        proxy_buffers            32 32k;
        proxy_busy_buffers_size  256k;
    }
}

Now my Browser Caching is showing successful:

After you update your NGINX and save the file you should just be able to Stop/Start your Local site to recompile those changes.

Let me know if that works for you!

Hey @Nick-B thanks for getting back.

I’ve replaced my nginx.conf.hbs contens for the one you’ve provided and restarted the LocalWP application, but all I get are 502 errors. Maybe I should do something different than replacing all the contents? Sorry for being so unexperienced on NGinx configuration, I hope that I can have it working at some point.

Thank you again for all your help and support, brother. Cheers!

Could you try disabling your other plugins @fabiofava and see if that makes a difference? Maybe something is conflicting on the site? Or you could try doing this on a new, blank site and see if it still 502s there. I think in my testing I also got a 502 but I was able to just refresh and it went away.

Hey @Nick-B!

I’ve tried to refresh, quit and reopen LocalWP then refreshing the page many times, but always got 502 on both my LocalWP sites. New sites seem to work with GZip but not the Browser Cache, I’ll need to further test this week but I’ll be a bit busy this week.

I get back as soon as I have some more info on the next days.

Thank you very much for your help and support, cheers!

Okay sounds good @fabiofava! You might also try reaching out to WPMU/Hummingbird to see if they can replicate any errors or if they have any other tips or tricks for setting this up locally that we are missing.

Hey @Nick-B I have some update:

I always add some instructions to the wp-config.php file before even starting a website for the first time. One of them is to enforce SSL/HTTPS on the WP-Admin so to have a more secured site:

define('FORCE_SSL_ADMIN', true);
define('FORCE_SSL_LOGIN', true);

These lines cause GZip not to work, removing them GZip works just fine. On the other hand, both with and without it the Browser Cache doesn’t work.

Anyway, even without all my wp-config.php codes, using your version of the nginx.conf.hbs won’t give me any other result than 502. Even on a recently created WP without any wp-config.php customization or any other plugin. Even clearing cookies and browser’s cache, it only gives me 502 screens.

I’ll keep looking forward from you on that brother. Hope we can find a way to have both GZip and Browser Cache working, specially with SSL/HTTPS.

Cheers!

What is your MacOS version @fabiofava? Just out of curiosity. Could you also share a Local Log here just in case anything stands out?

I would still encourage you to try reaching out to WPMU/Hummingbird since I’m unable to replicate this, it might be something specific to your device/setup or again maybe they have another recommendation for working locally that we’ve missed.

Hey @Nick-B thanks again for getting back!

I use Monterey 12.7.6 (last version supported by my Intel i7 2016 MBP wich I intend to keep for a few more years since it rocks). On the logs I tend to delete all logs after every session, but I’ll change again the nginx.conf.hbs file so to generate the eror, then send you the LocalWP log files from that session.

On the Hummingbird situation, as it works perfectly at their servers, and they don’t have (yet) their Hosting Connect to LocalWP, I assume they won’t dedicate too much resources on helping me out on that. Sites work, the only con is that it runs a bit slower, the WP-Admin is slower than I’d like it to be locally.

I’ve found out that GZip works under HTTP but not under HTTPS, but Browser Cache doesn’t work on both situations. I’ll reach them out again and refer to this (and the Connect) post(s), do to encourage them to take a deeper look on this issue, despite not being critical.

Thank you once again for your continued support, best regards brother!

Since you mentioned in our other thread that they use Local as well I’m just wondering if they have any tips/tricks for working locally. I’m sure you’re not the only user who’s tried!

Hey @Nick-B!

They probably don’t care, since the Hummingbird is an optimization plugin made basically to make sites faster online, and help their customers to comply to the Googletyranny Speed Scores and all that jazz…

I’d say they’ll say that the Hummingbird doesn’t need to be installed locally, like the Defender (their amazing security plugin) for obvious reasons. I always prefer to test the sites locally, exactly as they will be when published.

As I’m quite busy this week, I’ll probably be able to replicate the issue and send you the LocalWP Logs during the weekend (specially if there’s no paragliding this weekend), so please be patient if I take some time.

Cheers brother, stay well!

Hey @Nick-B !

I’ve finally had some time to do that. Spun a new WordPress site enforcing HTTPS/SSL on the WP Admin as ususal. Didn’t even try the Hummingbird, just pasted your contents into my nginx.conf.hbs and the 502s are there.

You’ll find attached my LocalWP Logs and also my wp-config.php file just in case.

local-lightning-verbose.log (21.7 KB)

local-lightning.log (5.3 KB)

And my wp-config.php file:

<?php

/**
 * The base configuration for WordPress
 *
 * The wp-config.php creation script uses this file during the installation.
 * You don't have to use the web site, you can copy this file to "wp-config.php"
 * and fill in the values.
 *
 * This file contains the following configurations:
 *
 * * Database settings
 * * Secret keys
 * * Database table prefix
 * * Localized language
 * * ABSPATH
 *
 * @link https://wordpress.org/support/article/editing-wp-config-php/
 *
 * @package WordPress
 * /

// ** Database settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'local' );

/** Database username */
define( 'DB_USER', 'root' );

/** Database password */
define( 'DB_PASSWORD', 'root' );

/** Database hostname */
define( 'DB_HOST', 'localhost' );

/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );

/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );

/* WP PHP Memory Settings */
define('WP_MEMORY_LIMIT', '256M');
define('WP_MAX_MEMORY_LIMIT', '512M');

/* Disable WordPress Updates */
define('WP_AUTO_UPDATE_CORE', false);
define('AUTOMATIC_UPDATER_DISABLED', true);

/**#@+
* Authentication unique keys and salts.
*
* Change these to different unique phrases! You can generate these using
* the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}.
*
* You can change these at any point in time to invalidate all existing cookies.
* This will force all users to have to log in again.
*
* @since 2.6.0
*/

define( 'AUTH_KEY',          'P)wl]Z5(60hy+,4UzlY.PX_n1vsdjhoeGT$mo.4f7&ayFvf%& ^%$-3Q@_ZepY9b' );
define( 'SECURE_AUTH_KEY',   '^Xyz$QV=OF!=x-NB3DAs^25)5;ko<LhIjMm@wHD5Fy%mEih=K`LEVuE*lwd&:z.@' );
define( 'LOGGED_IN_KEY',     'tYJh1&bWmZNXk[193BM/3cd<R@&AbtMj_OfUMXxDK*pO`=$A;y>Ng!]82{>y}r5=' );
define( 'NONCE_KEY',         'q!*G8`_?)3Pl[ngsDd~[X=-dn>3[1RK&rNi>[HzynU/2ro`y=fK]Qoh GLmm}<w,' );
define( 'AUTH_SALT',         'I*cRHd&m}sA}vmIz03c:sVEFZlV->ZKqX0*2zi_QPH%+|PWVzfO Xv+|aczy5kkS' );
define( 'SECURE_AUTH_SALT',  ']%lnZ{t@=|uM60^n`]EGPg71g1TYRY.YRT[M*K?psER(6YI)T9Ica5PhYP&&~3uo' );
define( 'LOGGED_IN_SALT',    'mk<|F9)8],I4GrA)}fa~|.bV$>H%__{2hUH2c;yYmiP&fHp%ea1g}p6P_Wy4|g&S' );
define( 'NONCE_SALT',        'y9#CJJDh%#tpmBD0.u1U<}aT9H K{ib_}Ji%=[U|S+2j1f,dzg[]?UPvyDJfq%ff' );
define( 'WP_CACHE_KEY_SALT', 'b}{V;=Li#s)j%^%RcVAoOw5<))[)3z/lA@RwOUJ*Ad7};9@Js>1v77h4b-&RgM4J' );

/**
* WordPress database table prefix.
*
* You can have multiple installations in one database if you give each
* a unique prefix. Only numbers, letters, and underscores please!
*/

$table_prefix = 'wp_';

/* Add any custom values between this line and the "stop editing" line. */

/**
* For developers: WordPress debugging mode.
*
* Change this to true to enable the display of notices during development.
* It is strongly recommended that plugin and theme developers use WP_DEBUG
* in their development environments.
*
* For information on other constants that can be used for debugging,
* visit the documentation.
*
* @link https://wordpress.org/support/article/debugging-in-wordpress/
*/

/* Prevent WordPress asking FTP credentials */
define('FS_METHOD','direct');

/* WordPress Debug Mode */
define('WP_DEBUG', false);
define('WP_DEBUG_LOG', false);
define('WP_DEBUG_DISPLAY', false);

/** Forces WordPress to load REST API **/
define('WP_REST_API_DISABLED', false);

/** Disable the Plugin and Theme Editor **/
define( 'DISALLOW_FILE_EDIT', true );

/** Enforce SSL on WP Login and WP Admin **/
define('FORCE_SSL_ADMIN', true);
define('FORCE_SSL_LOGIN', true);

/** LocalWP Environment **/
define( 'WP_ENVIRONMENT_TYPE', 'local' );

/* That's all, stop editing! Happy publishing. */

/* Inserted by Local by Flywheel. See: http://codex.wordpress.org/Administration_Over_SSL#Using_a_Reverse_Proxy */
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
$_SERVER['HTTPS'] = 'on';
}

/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) ) {
	define( 'ABSPATH', __DIR__ . '/' );
}

/** Sets up WordPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';

I hope you can find something to help on those.

Thank you very much once more for all your help and support.

Best regards