Support » Plugin: Easy FancyBox » [Plugin: Easy FancyBox] Easy Fancybox not working after switching hosts.

Viewing 15 replies - 1 through 15 (of 17 total)
  • Plugin Author RavanH

    (@ravanh)

    Well, yes. That same demo.4visions.nl site that you looked at before is running on Nginx + PHP-FPM and I’ve recently added WP Super Cache successfully ( after I changed one nginx rule, see http://wordpress.org/support/topic/plugin-wp-super-cache-only-home-page-super-cached-the-rest-always-from-wp-cache?replies=6 )

    The plugin file you are getting as a download instead of a stylesheet, tries to set the appropriate Content-type response header right at the start:

    header('Content-type: text/css; charset=utf-8', true);

    But your server config responds with “Content-Type: application/octet-stream” instead. It seems like the server does not pass processing of the file over to PHP-FPM at all. It might be the .css inside the file name that throws it off.

    Do you have access to your /etc/nginx/nginx.conf file? Can you tell me the PHP and maybe CSS related rules you see there?

    Plugin Author RavanH

    (@ravanh)

    Oh, and are you using Cloudflare? Any rules there that might be affecting this?

    Thank you for taking a look, RavanH!

    Here are the CSS, PHP, and cache rules, which is based on a tutorial by WP Mayor (http://www.wpmayor.com/articles/ultimate-guide-setting-wordpress-vps-part-3/). W3-TC is disabled right now and there is no minification set in Cloudflare.

    # Rewrite minified CSS and JS files
        location ~* \.(css|js) {
    		if (!-f $request_filename) {
                rewrite ^/wp-content/w3tc/min/(.+\.(css|js))$ /wp-content/w3tc/min/index.php?file=$1 last;
                # Use the following line instead for versions of W3TC pre-0.9.2.2
                #rewrite ^/wp-content/w3tc/min/([a-f0-9]+)\/(.+)\.(include(\-(footer|body))?(-nb)?)\.[0-9]+\.(css|js)$ $
            }
        }
    
        # Set a variable to work around the lack of nested conditionals
        set $cache_uri $request_uri;
    
        # POST requests and urls with a query string should always go to PHP
        if ($request_method = POST) {
            set $cache_uri 'no cache';
        }
        if ($query_string != "") {
            set $cache_uri 'no cache';
        }
    
        # Don't cache uris containing the following segments
        if ($request_uri ~* "(\/wp-admin\/|\/xmlrpc.php|\/wp-(app|cron|login|register|mail)\.php|wp-.*\.php|index\.php|$
            set $cache_uri "no cache";
        }
    
        # Don't use the cache for logged in users or recent commenters
        if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp\-postpass|wordpress_logged_in") {
            set $cache_uri 'no cache';
        }
    
        # Use cached or actual file if they exists, otherwise pass request to WordPress
        location / {
            try_files /wp-content/w3tc/pgcache/$cache_uri/_index.html $uri $uri/ /index.php;
        }
    
        # Cache static files for as long as possible
        location ~* \.(xml|ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz$
            try_files       $uri =404;
            expires         max;
            access_log      off;
        }
    
        # Deny access to hidden files
        location ~* /\.ht {
            deny            all;
            access_log      off;
            log_not_found   off;
        }
    
        # Pass PHP scripts on to PHP-FPM
        location ~* \.php$ {
            try_files       $uri /index.php;
            fastcgi_index   index.php;
            fastcgi_pass    127.0.0.1:9000;
            include         fastcgi_params;
            fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
            fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
        }
    }

    Also if it’s relevant, here’s my rewrite rule so everything has a www.

    rewrite ^(.*)       http://www.jonathanmanness.com$1 permanent;

    RavanH!!!! It works!!!

    I found your comments about WP and Nginx on another site (http://www.farinspace.com/wordpress-nginx-rewrite-rules/) and added this code to my Nginx Config:

    # unless the request is for a valid file, send to bootstrap
        if (!-e $request_filename)
        {
            rewrite ^(.+)$ /index.php? last;
        }

    Also, my config in the last post looks a little different now since I got W3-TC to send my settings to my NGINX config. The main thing though is that that request_filename code you shared fixed Easy Fancybox. Thank you, RavanH for all your help and for sharing your knowledge on the web!

    -Jon

    Plugin Author RavanH

    (@ravanh)

    I’m not an expert in Nginx rewrite rules but as far as I understand it, that is just a different way of saying:

    location / {
        try_files $uri /index.php;
    }

    which is (in a modified variation for W3TC) already in your rules. Or even a simple catch-all like error_page 404 /index.php; would do the same.

    Did you put the new if (!-e $request_filename) rule at the top of /etc/nginx/sites-available/default (or equivalent) maybe? If so, that will disable all subsequent rules (if it applies to the request) including this one:

    location ~* \.(css|js) {
    ...
    }

    which, I suspect, is the one that would be applied otherwise. You see, the file easy-fancybox.css.php falls under this rule since it holds true for any file with “.css” or “.js” in the name even when it’s not at the end. Putting a $ after (css|js) would change that…

    You need to make sure that sending to index.php / bootstrap is among the last rules applied, otherwise your W3TC rules might not be working optimally.

    Thank you the explanation, RavanH. My config has changed since what I posted above…here’s an updated one (removing my domain as well as root and log paths). You’ll notice that the bootstrap rule is after the W3-TC settings like you recommended.

    server {
        # Redirect yoursite.com to www.yoursite.com
        listen 80;
        server_name         yoursite.com;
        rewrite ^(.*)       http://www.yoursite.com$1 permanent;
    }
    server {
        # Tell nginx to handle requests for the www.yoursite.com domain
        listen 80;
        server_name         www.yoursite.com;
        index               index.php index.html index.htm;
        root                [path to public html folder]
        access_log          [path to access.log]
        error_log        [path to error.log]
    
        # Use gzip compression #deferring to W3-TC settings below
        # gzip_static       on;  # Uncomment if you compiled Nginx using --with-http_gzip_static_module
        # gzip                on;
        #gzip_disable        "msie6";
        #gzip_vary           on;
        #gzip_proxied        any;
        #gzip_comp_level     5;
        #gzip_buffers        16 8k;
        #gzip_http_version   1.0;
        # gzip_types          text/plain text/css application/json application/x-javascript text/xml application/xml appl$
    
        # Set a variable to work around the lack of nested conditionals
        set $cache_uri $request_uri;
    
        # POST requests and urls with a query string should always go to PHP
        if ($request_method = POST) {
            set $cache_uri 'no cache';
        }
        if ($query_string != "") {
            set $cache_uri 'no cache';
        }
    
        # Don't cache uris containing the following segments
        if ($request_uri ~* "(\/wp-admin\/|\/xmlrpc.php|\/wp-(app|cron|login|register|mail)\.php|wp-.*\.php|index\.php|wp$
            set $cache_uri "no cache";
        }
    
        # Don't use the cache for logged in users or recent commenters
        if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp\-postpass|wordpress_logged_in") {
            set $cache_uri 'no cache';
        }
    
        # Deny access to hidden files
        location ~* /\.ht {
            deny            all;
            access_log      off;
            log_not_found   off;
        }
    # BEGIN W3TC Minify cache
    location ~ /wp-content/w3tc/min.*\.js$ {
        types {}
        default_type application/x-javascript;
        expires modified 31536000s;
        add_header X-Powered-By "W3 Total Cache/0.9.2.4";
        add_header Vary "Accept-Encoding";
        add_header Pragma "public";
        add_header Cache-Control "max-age=31536000, public, must-revalidate, proxy-revalidate";
    }
    location ~ /wp-content/w3tc/min.*\.css$ {
        types {}
        default_type text/css;
        expires modified 31536000s;
        add_header X-Powered-By "W3 Total Cache/0.9.2.4";
        add_header Vary "Accept-Encoding";
        add_header Pragma "public";
        add_header Cache-Control "max-age=31536000, public, must-revalidate, proxy-revalidate";
    }
    location ~ /wp-content/w3tc/min.*js\.gzip$ {
        gzip off;
        types {}
        default_type application/x-javascript;
        expires modified 31536000s;
        add_header X-Powered-By "W3 Total Cache/0.9.2.4";
        add_header Vary "Accept-Encoding";
        add_header Pragma "public";
        add_header Cache-Control "max-age=31536000, public, must-revalidate, proxy-revalidate";
        add_header Content-Encoding gzip;
    }
    location ~ /wp-content/w3tc/min.*css\.gzip$ {
        gzip off;
        types {}
        default_type text/css;
        expires modified 31536000s;
        add_header X-Powered-By "W3 Total Cache/0.9.2.4";
        add_header Vary "Accept-Encoding";
        add_header Pragma "public";
        add_header Cache-Control "max-age=31536000, public, must-revalidate, proxy-revalidate";
        add_header Content-Encoding gzip;
    }
    # END W3TC Minify cache
    # BEGIN W3TC Page Cache cache
    location ~ /wp-content/w3tc/pgcache.*html$ {
        expires modified 3600s;
        add_header X-Powered-By "W3 Total Cache/0.9.2.4";
        add_header Vary "Accept-Encoding, Cookie";
        add_header Pragma "public";
        add_header Cache-Control "max-age=3600, public, must-revalidate, proxy-revalidate";
    }
    location ~ /wp-content/w3tc/pgcache.*gzip$ {
        gzip off;
        types {}
        default_type text/html;
        expires modified 3600s;
        add_header X-Powered-By "W3 Total Cache/0.9.2.4";
        add_header Vary "Accept-Encoding, Cookie";
        add_header Pragma "public";
        add_header Cache-Control "max-age=3600, public, must-revalidate, proxy-revalidate";
        add_header Content-Encoding gzip;
    }
    # END W3TC Page Cache cache
    # 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/xs$
    location ~ \.(css|js|htc)$ {
        expires 31536000s;
        add_header Pragma "public";
        add_header Cache-Control "max-age=31536000, 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 "max-age=3600, 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|q$
        expires 31536000s;
        add_header Pragma "public";
        add_header Cache-Control "max-age=31536000, 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
    # BEGIN W3TC Page Cache core
    rewrite ^(.*\/)?w3tc_rewrite_test$ $1?w3tc_rewrite_test=1 last;
    set $w3tc_rewrite 1;
    if ($request_method = POST) {
        set $w3tc_rewrite 0;
    }
    if ($query_string != "") {
        set $w3tc_rewrite 0;
    }
    if ($http_host != "www.yoursite.com") {
        set $w3tc_rewrite 0;
    }
    set $w3tc_rewrite3 1;
    if ($request_uri ~* "(\/wp-admin\/|\/xmlrpc.php|\/wp-(app|cron|login|register|mail)\.php|\/feed\/|wp-.*\.php|index\.p$
        set $w3tc_rewrite3 0;
    }
    if ($request_uri ~* "(wp\-comments\-popup\.php|wp\-links\-opml\.php|wp\-locations\.php)") {
        set $w3tc_rewrite3 1;
    }
    if ($w3tc_rewrite3 != 1) {
        set $w3tc_rewrite 0;
    }
    if ($http_cookie ~* "(comment_author|wp\-postpass|wordpress_\[a\-f0\-9\]\+|wordpress_logged_in)") {
        set $w3tc_rewrite 0;
    }
    if ($http_user_agent ~* "(W3\ Total\ Cache/0\.9\.2\.4)") {
        set $w3tc_rewrite 0;
    }
    set $w3tc_ua "";
    set $w3tc_ref "";
    set $w3tc_ssl "";
    if ($scheme = https) {
        set $w3tc_ssl _ssl;
    }
    set $w3tc_enc "";
    if ($http_accept_encoding ~ gzip) {
        set $w3tc_enc _gzip;
    }
    set $w3tc_ext "";
    if (-f "$document_root/wp-content/w3tc/pgcache/$request_uri/_index$w3tc_ua$w3tc_ref$w3tc_ssl.html$w3tc_enc") {
        set $w3tc_ext .html;
    }
    if ($w3tc_ext = "") {
      set $w3tc_rewrite 0;
    }
    if ($w3tc_rewrite = 1) {
        rewrite .* "/wp-content/w3tc/pgcache/$request_uri/_index$w3tc_ua$w3tc_ref$w3tc_ssl$w3tc_ext$w3tc_enc" last;
    }
    # END W3TC Page Cache core
    
    # unless the request is for a valid file, send to bootstrap
        if (!-e $request_filename)
        {
            rewrite ^(.+)$ /index.php? last;
        }
    
        # Pass PHP scripts on to PHP-FPM
        location ~* \.php$ {
            try_files       $uri /index.php;
            fastcgi_split_path_info ^(.+\.php)(/.*)$;
            fastcgi_index   index.php;
            fastcgi_pass    127.0.0.1:9000;
            include         fastcgi_params;
            fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
            fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
        }
    }

    See if you notice anything weird, but this config seems to make everything work including Easy Fancybox.

    Plugin Author RavanH

    (@ravanh)

    Can’t see anything funny…

    Does removing

    # unless the request is for a valid file, send to bootstrap
        if (!-e $request_filename)
        {
            rewrite ^(.+)$ /index.php? last;
        }

    still break the stylesheet? You see, that rule actually says something like “if a file does not exist, pass the request over to WordPress” which should not apply to a request for /wp-content/plugins/easy-fancybox/easy-fancybox.css.php?ver=1.3.4 (a file that should exist on your server, if it does not, there is something wrong with the plugin install)

    I’d say that the rule below it

    # Pass PHP scripts on to PHP-FPM
        location ~* \.php$ {
            try_files       $uri /index.php;
    ...
    }

    would apply to the request and pass it straight to PHP without going via WordPress… Which is exactly what should happen.

    Strange.

    I tried commenting out the bootstrap rule, but then my permalinks stopped working. Wish I understood the config rules better so I could keep tweaking, but everything on the front-end works great for now, which is good enough for me 🙂

    Plugin Author RavanH

    (@ravanh)

    I tried commenting out the bootstrap rule, but then my permalinks stopped working

    Right… that makes sence. It’s either that rule or one of the alternatives

    location / {
        try_files $uri /index.php;
    }

    or

    error_page 404 /index.php;

    but without one of those, request for non-existent files (which permalink are) will not be caught.

    I just cannot figure out why the request for the existing file /wp-content/plugins/easy-fancybox/easy-fancybox.css.php?ver=1.3.4 would fall overboard… Well, better not mess with your working setup just to find out this trivial thing. Good to know that it just works now 🙂

    By the way, are you working on a WP Multi-site or a regular WordPress installation? And how do you find W3TC performance? And does it not bite eShop, caching and serving a copy of someone else’s shopping cart or something?

    Regular WP installation. W3-TC has always worked great on a shared host and now works even better on a VPS with APC installed. For eshop pages (shopping cart, checkout, etc.), I set it so W3-TC doesn’t cache in order to avoid errors.

    Plugin Author RavanH

    (@ravanh)

    That’s good to hear… but do you know if that prevents the shopping cart menu item from being cached too? I mean whan someone adds something to cart, the cart menu item appears where it did not show before. If at that time stale cached pages are being replaced, I would expect the new cached pages to have that menu item there. And the cart widget, how do you exclude that one from being cached?

    Sorry to bother you with these questions but I work with eShop sometimes and I would like to get it running with caching to speed it all up, without any nasty side-effects.

    Ah shoot…just noticed that eShop fails to redirect to PayPal and complete the order. Didn’t work when turning off W3TC, either…probably another Nginx config issue. The plugin works as expected (widget and everything) until I get to shopping-cart/checkout?eshopaction=redirect

    Have you ever experienced this? (Sidenote: we totally hijacked your own forum talking about Nginx and eShop…hahaha)

    Just decided to deactivate eShop and switch to Easy Digital Download, which does work with my config and is better suited with my digital-download-only music.

    Plugin Author RavanH

    (@ravanh)

    Hmmm… have not seen that happen since I’m not using eShop on my Nginx server. But I wonder if it is because of that last question mark (?) after index.php in your Nginx rule…

    # unless the request is for a valid file, send to bootstrap
        if (!-e $request_filename)
        {
            rewrite ^(.+)$ /index.php? last;
        }

    Remove that question mark as WP should work without it and it might be causing the eshopaction=redirect request variable to be stripped.

    (Sidenote: we totally hijacked your own forum talking about Nginx and eShop…hahaha)

    Yep, and it’s my fault! Anyway, since you moved to Easy Digital Download and all is working now, let’s leave this thread alone 😉

    Thanks, RavanH! Before we close this out, eShop works after removing the ? in the rewrite rule. You’re a genius! Wanted to share in case you ever need to use eShop on an Nginx server.

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘[Plugin: Easy FancyBox] Easy Fancybox not working after switching hosts.’ is closed to new replies.