• Resolved G.lo

    (@glo-1)


    Hi there!
    I’m using the 1.3.0.rc1 version of the plugin. On my development machine I can make the plugin works great, using apache and the apache rewrite rules.
    But once I’ve put it on my production server that is using nginx, I can’t make it work at all. I’ve added the nginx rewrite rule to a bwp-minify.conf file that I call from within my wordpress-fastcache.conf file (I use nginx with fastcache). I’m not sure where I’m doing wrong. The bwp-minify rewrite rules are first, nginx is up and reloaded, the options are correct in the plugin, my cache folder is 777, but still, the generated files (minify-b1…) get a 404.

    As I was able to make it run with apache, I think my knowledge of how it works is quite ok. But now with my production server and nginx I have to admit that I’m lost on where I’m wrong, any idea what is causing the issue. Any idea?

    Thanks!

    https://www.ads-software.com/plugins/bwp-minify/

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author Khang Minh

    (@oddoneout)

    Couple of questions:

    1. Is your WP installation standard, i.e. a single WP located at https://example.com/ (index.php, wp-content, etc.)?
    2. By fastcache you mean fastcgi_cache? Is it possible that you post your .conf file here?
    3. Are you using any other cache plugin?
    4. Are you using any Nginx helper plugin?
    5. Is it possible that you post your nginx.conf or send it directly to me (contact(at)betterwp.net).

    Nginx is always a source of headaches, hope that we can get this figured out.

    Thread Starter G.lo

    (@glo-1)

    Hey, thanks for answering.

    1. Yep, standard. 1 site.
    2. Yep, fastcgi_cache. This is the part that I used for the cache:

    set $skip_cache 0;
    
    # POST requests and urls with a query string should always go to PHP
    if ($request_method = POST) {
    	set $skip_cache 1;
    }
    if ($query_string != "") {
    	set $skip_cache 1;
    }
    
    # Don't cache uris containing the following segments
    if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
    	set $skip_cache 1;
    }
    
    # Don't use the cache for logged in users or recent commenters
    if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
    	set $skip_cache 1;
    }
    
    #include /etc/nginx/conf.sites/bwp-minify.conf;
    
    location ~ .php$ {
            location ~* wp\-login\.php {
                    limit_req zone=one burst=1 nodelay;
                    include fastcgi_params;
                    fastcgi_pass php5-fpm-sock;
                    limit_req_status 403;
            }
    
            try_files $uri /index.php;
            include fastcgi_params;
            fastcgi_pass php5-fpm-sock;
    
            fastcgi_cache_bypass $skip_cache;
            fastcgi_no_cache $skip_cache;
    
            fastcgi_cache WORDPRESS;
            fastcgi_cache_valid  60m;
    }
    
    location ~ /purge(/.*) {
            fastcgi_cache_purge WORDPRESS "$scheme$request_method$host$1";
    }

    3. I use W3 Total Cache just for database and object cache.
    4. Yep, the Nginx helper plugin from rtcamp.
    5. I’m gonna post the nginx.conf. Also because I couldn’t find where the issue was, I’ve removed all the wordpress plugins and I’ve made the simplest conf file I can do (no fastcgi_cache, no cache at all) and because it still doesn’t work, I’m going to post this one. If you need the more complicated one with the cgi_cache let me know.
    nginx.conf

    user www-data;
    worker_processes 8;
    pid /run/nginx.pid;
    
    events {
    	worker_connections 768;
    	# multi_accept on;
    }
    
    http {
    	add_header rt-Fastcgi-Cache $upstream_cache_status;
    	limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;
    
    	##
    	# Basic Settings
    	##
    
    	sendfile on;
    	tcp_nopush on;
    	tcp_nodelay on;
    	keepalive_timeout 65;
    	types_hash_max_size 2048;
    	# server_tokens off;
    
    	# server_names_hash_bucket_size 64;
    	# server_name_in_redirect off;
    
    	include /etc/nginx/mime.types;
    	default_type application/octet-stream;
    
    	##
    	# Logging Settings
    	##
    
    	access_log /var/log/nginx/access.log;
    	error_log /var/log/nginx/error.log;
    
    	##
    	# Gzip Settings
    	##
    
    	gzip on;
    	gzip_disable "msie6";
    
    	gzip_vary on;
    	gzip_proxied any;
    	gzip_comp_level 6;
    	gzip_buffers 16 8k;
    	gzip_http_version 1.1;
    	gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    
    	##
    	# nginx-naxsi config
    	##
    	# Uncomment it if you installed nginx-naxsi
    	##
    
    	#include /etc/nginx/naxsi_core.rules;
    
    	##
    	# nginx-passenger config
    	##
    	# Uncomment it if you installed nginx-passenger
    	##
    
    	#passenger_root /usr;
    	#passenger_ruby /usr/bin/ruby;
    
    	##
    	# Virtual Host Configs
    	##
    
    	include /etc/nginx/conf.d/*.conf;
    	include /etc/nginx/sites-enabled/*;
    }

    site conf

    server {
            server_name wp.sleeplessmind.info;
    
            access_log   /var/log/nginx/wp.sleeplessmind.info.access.log;
            error_log    /var/log/nginx/wp.sleeplessmind.info.error.log;
    
            root /srv/www/wordpress/public_html;
            index index.php;
    
            location / {
                    try_files $uri $uri/ /index.php?$args;
            }
    
            # BEGIN BWP Minify WP Rules
            # BEGIN BWP Minify Headers
            location ~ /wp-content/plugins/bwp-minify/cache/.*\.(js|css)$ {
                add_header Cache-Control "public, max-age=7200";
                add_header Vary "Accept-Encoding";
                etag off;
            }
            location ~ /wp-content/plugins/bwp-minify/cache/.*\.js\.gz$ {
                gzip off;
                types {}
                default_type application/x-javascript;
                add_header Cache-Control "public, max-age=7200";
                add_header Content-Encoding gzip;
                add_header Vary "Accept-Encoding";
                etag off;
            }
            location ~ /wp-content/plugins/bwp-minify/cache/.*\.css\.gz$ {
                gzip off;
                types {}
                default_type text/css;
                add_header Cache-Control "public, max-age=7200";
                add_header Content-Encoding gzip;
                add_header Vary "Accept-Encoding";
                etag off;
            }
            # END BWP Minify Headers
            set $zip_ext "";
            if ($http_accept_encoding ~* gzip) {
                set $zip_ext ".gz";
            }
            if (-f $request_filename$zip_ext) {
                rewrite (.*) $1$zip_ext break;
            }
            if (!-e $request_filename) {
                rewrite ^/wp-content/plugins/bwp-minify/cache/minify-b(\d+)-([a-zA-Z0-9-_.]+)\.(css|js)$ /index.php?blog=$1&min_group=$2&min_type=$3;
            }
            # END BWP Minify WP Rules
    
            location ~ \.php$ {
                    try_files $uri =404;
                    include fastcgi_params;
                    fastcgi_pass php5-fpm-sock;
            }
    }

    Thanks for the help! Greatly appreciated.

    Thread Starter G.lo

    (@glo-1)

    Well actually now with the simplest site conf it works. No 404, the files are written in the cache and used correctly.

    Let me post the full conf with fastcgi_cache then. Maybe there’s a rule somewhere that overrides the ones of BWP-Minify that I cannot see.

    Thread Starter G.lo

    (@glo-1)

    Alright I found the issue. In my wordpress-global.conf file I had a

    location /wp-content/ { internal; }

    that was probably preventing the browser to access the generated files.
    I’ve removed the line and things are working fine now!

    Thread Starter G.lo

    (@glo-1)

    Ok after some other tests, it appears that it doesn’t work if I use the fastcgi_cache. It works the first time and at the second refresh of the browser, all the js and css are lost. Will investigate.

    Thread Starter G.lo

    (@glo-1)

    My mistake! Sorry. The problem was not with the fastcgi_cache, it was that in production I forgot to add the rewrite rules. Now things are working fine. So it was just the internal blocking. Thanks again!

    Plugin Author Khang Minh

    (@oddoneout)

    Ah good catch! That internal directive was easily overlooked.

    Glad you got it working, may I make this topic sticky so others might see?

    Enjoy the plugin.

    Thread Starter G.lo

    (@glo-1)

    Yeah, I actually misunderstood this directive when I used it.
    Please be my guest, hope it can help others! Cheers. I’ll follow the plugin closely, you seem to have a good roadmap!

    Plugin Author Khang Minh

    (@oddoneout)

    Could you please do me a favour and edit the first post’s title to become:
    [resolved] 404 .... on nginx server

    That will make it a little more descriptive.

    Thanks.

    Thread Starter G.lo

    (@glo-1)

    Well I would love to do that, but I can’t find the way to edit it??

    Plugin Author Khang Minh

    (@oddoneout)

    Ops sorry, editing seems to be disabled after the post has been submitted for some time. Let’s leave it as is then ??

    Thread Starter G.lo

    (@glo-1)

    Alright. A pity though, you’re right it would be nice to specify more the titles of the posts once the issue has been found. Could be very helpful to others!

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘404 for combined and minified files’ is closed to new replies.