1

gzip compression is working for html pages, but not for css or js, I've found several similar questions, including the following, and tried the suggested solutions, I've tried various settings for (gzip_buffers, gzip_min_length, gzip_comp_level) but none have worked.

What else could be affecting this, why aren't the js or css files compressed?

NGINX gzip not compressing JavaScript files

nginx gzip compression not working

enable gzip compression with nginx

I have the following http block in nginx conf:

http {

    upstream fastcgi_backend {
            server 127.0.0.1:9000;
    }

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    access_log off;

    #access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    # Enable Gzip compression
    gzip          on;

    gzip_vary on;
    gzip_buffers 128 4k;

    # Compression level (1-9)
    gzip_comp_level     5;

    # Don't compress anything under 256 bytes
    gzip_min_length     256;

    # Compress output of these MIME-types
    gzip_types
        application/atom+xml
        application/javascript
        application/json
        application/rss+xml
        application/vnd.ms-fontobject
        application/x-font-ttf
        application/x-font-opentype
        application/x-font-truetype
        application/x-javascript
        application/x-web-app-manifest+json
        application/xhtml+xml
        application/xml
        font/eot
        font/opentype
        font/otf
        image/svg+xml
        image/x-icon
        image/vnd.microsoft.icon
        text/css
        text/plain
        text/javascript
        text/x-component;

    # Disable gzip for bad browsers
    gzip_disable  "MSIE [1-6]\.(?!.*SV1)";

    # allow the server to close connection on non responding client, this will free up memory
    reset_timedout_connection on;

    # request timed out -- default 60
    client_body_timeout 10;
}
2
  • 1
    what does your server block config look like? That may be overriding your http block Commented Apr 28, 2020 at 13:59
  • there isn't a server block, I've recently been given responsibility for this server and it seems to have been set up very minimally. Commented Apr 28, 2020 at 14:04

1 Answer 1

2

Check the conf.d folder for other conf files that may be overriding nginx.conf, you should see at least one file with a server block for the hostname/IP Nginx is serving. Looks like this:

server {
    listen 80;
    listen [::]:80;
    server_name example.com;

    return 301 https://example.com$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name example.com;

    ...
}

You can always search for the server blocks: $ grep -rl "server_name" /etc/nginx

2
  • The only file in the conf.d folder is ssl.conf, which doesn't have any overriding blocks.EDIT, ah, yes there is another conf file, it's in the 'sites-available' folder. Commented Apr 28, 2020 at 14:17
  • 1
    "nginx -T" show full config. just research it. From my point of view it must to work. Commented Aug 7, 2020 at 13:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.