WordPress.org

Ready to get started?Download WordPress

Forums

W3 Total Cache
Minify URL rewriting not working on nginx (4 posts)

  1. Daniel Tara
    Member
    Posted 2 years ago #

    Hi,

    I have setup a WordPress installation with W3 Total Cache on a nginx server. I am using the minify option with Opcode APC and automatic mode. I am receiving the following error after activating this option:

    It appears Minify URL rewriting is not working. If using apache, verify that the server configuration allows .htaccess or if using nginx verify all configuration files are included in the configuration.

    In nginx.conf I have what the plugin suggested me to put, namely this:

    # BEGIN W3TC Minify core
    rewrite ^/usr/share/nginx/html/wp-content/w3tc/min/w3tc_rewrite_test$ /usr/share/nginx/html/wp/wp-content/w3tc/min/index.php?w3tc_rewrite_test=1 last;
    rewrite ^/usr/share/nginx/html/wp-content/w3tc/min/(.+\.(css|js))$ /usr/share/nginx/html/wp/wp-content/w3tc/min/index.php?file=$1 last;
    # END W3TC Minify core

    If I disable the URL rewriting for minify, the request returns a 400 status.

    Any idea what I may be doing wrong?

    http://wordpress.org/extend/plugins/w3-total-cache/

  2. haddow777
    Member
    Posted 2 years ago #

    I can see an issue. Your rewrites have "html/wp-content" but then down the line the location uses "html/wp/wp-content". Do you actually have wordpress installed in a directory above the the main site directory?

    If you do, I have found that there is an bug in W3TC that messes up Minify rewrites. You can find the fix here.

    If you haven't installed into another directory, I'm not sure why your rewrites are messed up. Try manually removing the "wp/" directory from the rewrite statements and see what happens.

    I hope this helps some.

  3. Daniel Tara
    Member
    Posted 2 years ago #

    Thank you haddow777. I am indeed hosting WordPress in a subdirectory. I have done the modifications suggested by you in that topic and now my rewrite rules look like this:

    # BEGIN W3TC Minify core
    rewrite ^/usr/share/nginx/html/wp/wp-content/w3tc/min/w3tc_rewrite_test$ /usr/share/nginx/html/wp/wp-content/w3tc/min/index.php?w3tc_rewrite_test=1 last;
    rewrite ^/usr/share/nginx/html/wp/wp-content/w3tc/min/(.+\.(css|js))$ /usr/share/nginx/html/wp/wp-content/w3tc/min/index.php?file=$1 last;
    # END W3TC Minify core

    However no functionality change. Minified URLs with rewrite return 404 and with GET variables return 400.

    Maybe I have the rewrite rules in the wrong place? I have put them inside the server block outside any locations as I have read that is the recommended location for rewrites.

  4. haddow777
    Member
    Posted 2 years ago #

    Hmmm. That's weird. My fix shouldn't have affected the actual rewrites. The bug I had fixed as mentioned in my other post was only affecting the test W3TC does to check if the Minify rewrite is working. The actual rewrite code itself was working, at least in my version.

    Are you using 9.2.4?

    Are these rewrites the ones from the automatically generated nginx.conf file in your base web directory where WP was installed to? I simply made an include at the bottom of my server block to the generated nginx.conf in the WP root directory.

    Here is what is in my file on my test server:

    rewrite ^/wp/wp-content/w3tc/min/w3tc_rewrite_test$ /wp/wp-content/w3tc/min/    index.php?w3tc_rewrite_test=1 last;
    rewrite ^/wp/wp-content/w3tc/min/(.+\.(css|js))$ /wp/wp-content/w3tc/min/index. php?file=$1 last;

    Well, I can see a major difference right away. Yours has "^/user/share/nginx/html/wp" whereas mine has "^/wp". Maybe that is causing the issue.

    Hope that helps.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic