CDN not use gzip, header in nginx
-
Good day! When we use CDN it take full file not gzip?
Second question: header is not used. I think its because my server use nginx for static files. I need to add rules in nginx conf?
-
del
If you use nginx to serve static files and pass PHP requests to Apache you must set headers manually in nginx conf, but only when you’re using friendly minify url.
Currently you won’t be able to see the nginx rules because the plugin will detect that you’re on Apache.
Anyway, try putting these rules into your nginx conf for a proper header:
# BEGIN BWP Minify Rules # BEGIN BWP Minify Headers location ~ /wp-content/plugins/bwp-minify/cache/.*\.(js|css)$ { add_header Cache-Control "public, max-age=86400"; 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=86400"; 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=86400"; add_header Content-Encoding gzip; add_header Vary "Accept-Encoding"; etag off; } # END BWP Minify Headers # END BWP Minify Rules
Dont know why but its not working. My nginx version is 0.7.3 so no support for etag, i remove it. Can i use “expires” and not cache-control? In images i use expires and all work fine.
Yes you can use “expires” instead. Note that you need to enable friendly minify url for this to work. Try flushing all CDN’s cache as well.
Expires not work too. Maybe there is a error in code you provided? I am not good coder. Sorry.
Take a look at the second FAQ item here: http://betterwp.net/wordpress-plugins/bwp-minify/faq/ and make sure that you put the above codes at the recommended position.
If that doesn’t work you can post your conf file here so I can take a look.
Yep i read that info but cant make work headers.
I use friendly url. All files in folder /cache/m/
Thats my nginx confserver { server_name site.com www.site.com; listen 000.00.000.0; set $root_path /var/www/user/data/www/site.com; location ~* ^.+\.(svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ { root $root_path; access_log /var/www/nginx-logs/user isp; access_log /var/www/httpd-logs/site.com.access.log ; error_page 404 = @fallback; } location / { proxy_pass http://000.00.000.0:81; proxy_redirect http://000.00.000.0:81/ /; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Real-IP $remote_addr; } location ~* ^/(webstat|awstats|webmail|myadmin|pgadmin)/ { proxy_pass http://000.00.000.0:81; proxy_redirect http://000.00.000.0:81/ /; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Real-IP $remote_addr; } location @fallback { proxy_pass http://000.00.000.0:81; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Real-IP $remote_addr; } # BEGIN BWP Minify Rules # BEGIN BWP Minify Headers location ~ /cache/m/.*\.(js|css)$ { add_header Cache-Control "public, max-age=86400"; add_header Vary "Accept-Encoding"; } location ~ /cache/m/.*\.js\.gz$ { gzip off; types {} default_type application/x-javascript; add_header Cache-Control "public, max-age=86400"; add_header Content-Encoding gzip; add_header Vary "Accept-Encoding"; } location ~ /cache/m/.*\.css\.gz$ { gzip off; types {} default_type text/css; add_header Cache-Control "public, max-age=86400"; add_header Content-Encoding gzip; add_header Vary "Accept-Encoding"; } # END BWP Minify Headers # END BWP Minify Rules location ~* ^.+\.(jpg|jpeg|gif|png|swf|tiff|swf|flv)$ { root $root_path; expires 1y; } include /usr/local/ispmgr/etc/nginx.inc;
Ah, I see. Since your site’s setup is different additional rule is needed. Replace from
# BEGIN BWP Minify Rules
to# END BWP Minify Rules
with:# BEGIN BWP Minify Rules # BEGIN BWP Minify Headers location ~ /cache/m/.*\.(js|css)$ { add_header Cache-Control "public, max-age=86400"; add_header Vary "Accept-Encoding"; } location ~ /cache/m/.*\.js\.gz$ { gzip off; types {} default_type application/x-javascript; add_header Cache-Control "public, max-age=86400"; add_header Content-Encoding gzip; add_header Vary "Accept-Encoding"; } location ~ /cache/m/.*\.css\.gz$ { gzip off; types {} default_type text/css; add_header Cache-Control "public, max-age=86400"; add_header Content-Encoding gzip; add_header Vary "Accept-Encoding"; } # 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; } # END BWP Minify Rules
You won’t probably need
expires
btw.Looks like i found problem. After flushing cache in BWM. First time when we loading page we get version of minified files that match with version in settings of BWM and those files with right headers even without rules in nginx config (looks like used htaccess rules), but when we loading pahe second time the version of files is changing to version number +16. First time its 1400777 second it will be 1400793 and those files with Cache-Control max-age=0″
That means you’re having a default rule set somewhere that make js/css file served with a
modified 16
expire header. But if you put the latest rules I mentioned above in an appropriate place it should overwrite that default rule.I mean that first time file have url http://site.com/cache/m/minify-b1–668946cad3ad601e7d9a5680b14567f1.css?ver=1408781714
The second it will be http://site.com/cache/m/minify-b1–668946cad3ad601e7d9a5680b14567f1.css?ver=1408781730Ahh sorry its ok with version. Looks like it just so work. After second loading of page version of file is changing +14.
Ah, that’s because you’re adding the cache folder’s last modified timestamp as the cache buster. Just go to BWP Minify > General Options > Plugin Functionality and then set
For cache buster, use
to something else.Looks like the problem because of this one
location ~* ^.+\.(svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ { root $root_path; access_log /var/www/nginx-logs/user isp; access_log /var/www/httpd-logs/site.com.access.log ; error_page 404 = @fallback; }
I think it owerwrite rules from your post. But i just use it like it now. Expires is not so important now. Plus to this i get 304 response to minify files.
- The topic ‘CDN not use gzip, header in nginx’ is closed to new replies.