Forum Replies Created

Viewing 15 replies - 1 through 15 (of 21 total)
  • Ddutra,

    I also use nginx to serve out static files and the first thing that I wanted to change was their compressed file naming, both .gzip and _gzip should really be .gz because most servers are already setup to serve out a .gz file.

    The way that w3tc does it is with rewrite. If a browser accepts gzip compression then it rewrites the file name to .gzip or _gzip if you are using page cache, then it changes the headers. It does not use gzip_static.

    From your description it seems like your nginx rewrite code has a problem because it’s not finding the static file and ends up using php to serve out the js or css files. When everything is correct it only uses /wp-content/plugins/w3-total-cache/pub/minify.php once to create the minimized regular and compressed file.

    What I do is add an extra small header in the rewrite code so that I know rewrite is working correctly, then once you know it’s correct just comment out the temporary header.

    Here is a post that shows my nginx configuration:
    https://www.ads-software.com/support/topic/prefer-gz-instead-of-gzip?replies=5

    Craig

    Ddutra,

    Oops, sorry I misread your post and started talking about page caching. The way the compressed css and js files are named is with .gzip.

    The settings I use are:

    General Settings Page:
    Minify mode: Auto
    Minify cache method: Disk

    Browser Cache Page: under css and js:
    Check “Enable HTTP (gzip) compression”.

    Minify Page:
    Check the “Rewrite URL structure”
    enable “JS minify settings:” and “CSS minify settings:”.

    My guess is that since your setup isn’t saving .gzip files, the “Enable HTTP (gzip) compression” isn’t checked.

    Craig

    Ddutra,

    For the “Page cache method:” you should try using Disk Enhanced. Then the files are written to the cache directory in both .html and .html_gzip. The default level of compression is 9.

    First make sure that the files are being written to the /wp-content/cache/page_enhanced/your.domain.com directory. Then you need to make sure that the rewrite in nginx is written correctly so that it can find the file and serve it out using the .html_gzip file (not named .gz) and send the correct headers. If it can not find the file then it’s generated on the fly.

    If everything is set up correctly it will serve out the static .html_gzip file which is quite fast using nginx.

    Craig

    Bobk88,
    Thanks for the explanation. I have always just used the auto mode, so I didn’t spot those other options.

    I should also mention that when you use the non-blocking JS method that you might need to rewrite some of the other plugins js because the jquery will get loaded after any js that’s in the page.

    Craig

    Thread Starter almooj-craig

    (@almooj-craig)

    Martin,

    Thanks for the link, just what I needed. First I applied the configuration setting to a 3.6 blog. It didn’t quite work because I needed to add the new server name to the Ngnix configuration. Once that was updated it worked as expected.

    Then I made those changes to a 3.6 MU blog. That was a little tricky because you need to create a single new domain name that will be used by all the blogs, but of course there is no blog that goes with that name so when the css and js files need to be generated it just tries to do a 301 to wp-signup.php.

    So basically you need the correct blog to generate the minimized js and css files, too bad the main parent 000000 minify.php doesn’t just put css and js into the correct blog number that is based on the blog number that’s in the file= query parameter.

    Here is my solution using mod_rewrite in Apache. The subdomain that does not use cookies is similar to a.blog.somedomain.org

    <Directory "/zzz/blog/htdocs/wp-content/cache/minify">
    	RewriteEngine On
    
    	RewriteCond %{HTTP_HOST} a.blog.somedomain.org$ [NC]
    	RewriteCond %{REQUEST_URI} 000004 [NC]
    	RewriteRule .* - [E=BLOG:action.]
    	RewriteCond %{REQUEST_URI} 000006 [NC]
    	RewriteRule .* - [E=BLOG:housing.]
    	RewriteCond %{REQUEST_URI} 000007 [NC]
    	RewriteRule .* - [E=BLOG:financial.]
    	RewriteCond %{REQUEST_URI} 000008 [NC]
    	RewriteRule .* - [E=BLOG:health.]
    	RewriteRule ^(.+\.(css|js))$ https://%{ENV:BLOG}blog.somedomain.org/wp-content/plugins/w3-total-cache/pub/minify.php?file=$1 [L]
    
    	RewriteBase /wp-content/cache/minify/
    	RewriteRule /w3tc_rewrite_test$ ../../plugins/w3-total-cache/pub/minify.php?w3tc_rewrite_test=1 [L]
    	RewriteCond %{HTTP:Accept-Encoding} gzip
    	RewriteRule .* - [E=APPEND_EXT:.gzip]
    	RewriteCond %{REQUEST_FILENAME}%{ENV:APPEND_EXT} -f
    	RewriteRule (.*) $1%{ENV:APPEND_EXT} [L]
    	RewriteRule ^(.+/[X]+\.css)$ ../../plugins/w3-total-cache/pub/minify.php?test_file=$1 [L]
    	RewriteRule ^(.+\.(css|js))$ ../../plugins/w3-total-cache/pub/minify.php?file=$1 [L]
    </Directory>

    Since there are only 4 active blogs, I did it that way. If you had a lot of blogs then using RewriteMap that searches the tables would work better.

    Thanks Again,
    Craig

    I’m glad you got it working! Thanks for posting your config files, it’s interesting to read other examples. I like how you use include /etc/nginx/sites-enabled/*;, I just got in the habit of putting everything in the config file, perhaps I’ll change someday.

    I noticed that you use Varnish as a caching server. Does that seem to reduce a lot of load from Ngnix. In my configuration I use Ngnix without any PCP to serve out static files and then I allow Apache to do everything else. Do you think throwing Varnish into the mix would make it even more efficient?

    Craig

    When I was first trying to configure W3TC, I noticed that if that checkbox was unchecked, then W3TC would generate the files in the following directory, because it used minify.php directly in the url.
    /wp-content/cache/minify/000000

    When the box was checked, the files were removed and then they are generated when the file isn’t there by doing a rewrite that points to the minify.php file.

    Craig

    When you uncheck that box, did you look in your cache files and see if the css and js files are there.

    Did you read through my configuration and the one that W3TC generated to see what the difference is?

    There must be something amiss with your ngnix configuration because mine works without a problem on several different WP installations.

    Once you confirm that the minify.php file is working correctly then you can switch back and let rewrite do the work.

    Did you put the code that W3TC generated into your config file?

    Here is a link to my ngnix.conf file that may help you get your rewrite configuration working correctly.
    https://www.ads-software.com/support/topic/prefer-gz-instead-of-gzip?replies=5

    Craig

    I know you are using nginx, I was just talking generically about rewrite.

    I use nginx for static files and it works as long as you have the correct rewrite rules in the server and location of your config file.

    Did you try un-checking the Rewrite URL structure
    If disabled, CSS and JS embeddings will use GET variables instead of “fancy” links. box.

    That will tell you that the plugin works correctly but that somehow your rewrite in Apache or in your case nginx is not correct.

    Craig

    If you look in your cache directory and the css an js files are not there, most likely you have a mod_rewrite problem.

    Until you get it sorted out, There is an option in the Minify section that does not use mod_rewrite to create the files, it directly calls the minify.php file.

    —-
    Rewrite URL structure
    If disabled, CSS and JS embeddings will use GET variables instead of “fancy” links.
    —-

    If after unchecking that box the files start showing up in your cache directory then you know that W3TC can create the files and write them.

    When you check that option, mod_rewrite will point to the minify.php file.

    RewriteRule ^(.+\.(css|js))$ ../../plugins/w3-total-cache/pub/minify.php?file=$1 [L]

    So basically you need to make sure that your server is processing the .htaccess file and that it’s there. If you don’t process .htaccess files then it needs to be in your virtual host, same with ngnix.

    Craig

    Most likely the site was not rendering correctly because there was a problem with the css minify settings.

    If you were using “Page Enhanced” for caching the pages then even removing the plugin will not stop the pages from being cached, because it never even loads WP, that’s why it’s quicker. Basically you will need to remove the cache files manually.

    Craig

    I am using 0.9.3 and all of the options you list are not available. What version are you using?

    I don’t get any options about where to place the JS on the page, it only displays before </head> and the other options are JS, async and defer.

    Generally when I load JS files it usually works best if you use the non-blocking JS method. That way the page can continue to load and onload and oncomplete work correctly for JS that’s embedded on the page.

    Craig

    Most likely it’s a permission problem. Check your files and make sure that they are writable by your web server. I normally don’t use the automated installation programs but if WP uses FTP to create directories and files, then your files and directories would also need to be writable by your FTP user name.

    Craig

    I have never used an automatic upgrade for plugins or WP. Normally the way I do it is to deactivate the old plugin. Then rename the old plugin directory by adding the version after the directory name. Then I unzip the plugin files and manually install them into the wp-content directory.

    I think for W3TC I also manually removed the cache directories, so that there would be no old cache files lurking around.

    Then I activated the W3TC plugin and configured it. Once I got the correct mod_rewrite installed in the virtual host, minimize worked correctly and enhanced page cache also worked correctly on all of the installations. A couple were upgrades from an older W3TC and one was a Super Cache. Once everything works correctly I remove the old directory from the server.

    If you don’t feel comfortable trying that method, then just use the older version until the next W3TC comes out. You should also have a backup before you modify the site.

    Craig

Viewing 15 replies - 1 through 15 (of 21 total)