nginx gzip compression doesn't seem to work - nginx

I'm trying to figure out why my custom CDN on nginx, doesn't appear to be working. Here is what I have in my site configuration:
server {
listen 80;
listen [::]:80;
server_name cdn.site.co.uk;
root /srv/www/site.co.uk/bob_user;
if ($uri !~ "\.(gif|jpe?g|png|js|css|eot|woff|ttf|svg)$") {
rewrite ^/(.*)$ https://site.co.uk/ permanent;
}
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;
}
The file itself works - but using this tool, it tells me that it does:
https://varvy.com/tools/gzip/
This is the URL I tested:
http://cdn.businessofbrands.co.uk/wp-includes/js/jquery/jquery.js
I'm a bit confused as to why this is. Could anyone shed some light?

It looks like application/javascript is missing from gzip_types.
You'll want to add it to the following line:
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;
Actually, text/javascript is obsolete so you could just replace it :)

Related

nginx serves 404 without passing to proxy

I' ve got simple setup to deploy angular, springboot, mysql stack. I'am serving this through nginx, with this configuration
server {
listen 8081;
server_name _;
root /usr/share/nginx/html;
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_min_length 32;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript font/opentype image/svg+xml image/x-icon application/javascript application/x-font-ttf application/x-font-otf application/font-woff application/font-woff2 application/vnd.ms-fontobject application/octet-stream;
error_log stderr info;
access_log /dev/stdout main;
location /api {
proxy_pass http://backend:8080/;
}
location /app {
root /usr/share/nginx/html;
try_files $uri$args $uri$args/ $uri/ /index.html;
#index index.html index.htm;
}
}
app is served well, but when i try to get localhost:8081/api it ends with 404, and in logs i've see that nginx end with 404, without passing to backend. Am i doing something wrong?

Nginx enable gzip

I want enable the gzip compression on my nginx server. The nginx.conf file is here:
http {
# Enable Gzip
server {
location ~* \.(?:ico|woff|css|js|gif|jpe?g|png)$ {
expires 30d;
add_header Pragma public;
add_header Cache-Control "public";
}
location /api {
try_files $uri $uri/ /api/index.php;
}
location / { ##merge
gzip on;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_proxied any;
gzip_types
# text/html is always compressed by HttpGzipModule
text/css
text/javascript
text/xml
text/plain
text/x-component
application/javascript
application/json
application/xml
application/rss+xml
font/truetype
font/opentype
application/vnd.ms-fontobject
image/svg+xml;
gzip_static on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
gzip_vary on;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" { add_header "" ""; }
location ~ "^/ngx_pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon" { }
}
}
Unfortunately the gzip compression not working, Google Pagespeed and Gtmetrix not detect this.
Where can I place the gzip conf?
In The http{} server{} or location{} tag?
I already tried in the http and in the location tags too
You can put the gzip configuration anywhere, but if you want to apply it to all websites / files it is best to put it in the http section - this will then be the default for all server and location blocks. I would also "shorten" / change your config to the following:
http {
gzip on;
gzip_min_length 500;
gzip_proxied any;
gzip_comp_level 4;
gzip_types text/css text/javascript text/xml text/plain text/x-component application/javascript application/json application/xml application/rss+xml font/truetype font/opentype application/vnd.ms-fontobject image/svg+xml;
gzip_vary on;
gzip_disable "msie6";
... here come your server blocks / rest of your config
}
I use that configuration and it works fine for me - you can also test it in your browser first (for example with Firebug) before testing it with external services.
Using gzip_static only makes sense if you actually generate gzipped files for Nginx (as filename + .gz), so this has nothing to do with enabling gzip and should only be a possible second step.

Nginx does not compress js

My Nginx webserver does not compress js files with gzip.
Config follows:
gzip on;
gzip_min_length 1100;
gzip_buffers 4 32k;
gzip_types text/plain application/xml text/css text/js text/xml application/x-javascript text/javascript application/json application/xml+rss;
gzip_vary on;
gzip_comp_level 5;

nginx gzip not compressing mp4

Any ideas why my gzip conf is not compressing mp4 and jpg?s
nginx.conf includes my gzip file
#gzip on;
include /etc/nginx/gzip;
--
gzip on;
gzip_http_version 1.0;
gzip_disable "MSIE [1-6]\.";
gzip_buffers 16 8k;
gzip_min_length 1100;
gzip_comp_level 2;
gzip_proxied any;
gzip_types video/mp4 text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript image/jpeg;

Use LZF Compression instead GZIP with NginX

Is there a way to change the handler for compression from gzip to lzf in nginx ?
Actual config:
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_min_length 1024;
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;
can be it translated to ?
lzf on;
..
..

Resources