CSS and Javascript files are not Gzipped in Nginx

Hello everyone,

I can't find a solution on how to enable gzip for css and javascript files for nginx. Html files are gzipped without a problem. Gzip was enabled by default. What could be the reason that html is gzipped but not css or js files? Thank you for your help.

Output from config:

sendfile on;

tcp_nopush on;

tcp_nodelay on;

keepalive_timeout 65;

typeshashmax_size 2048;

server_tokens off;

servernameshashbucketsize 64;

servernamein_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;

gzipcomplevel 2;

gzip_buffers 16 8k;

gziphttpversion 1.1;

gzip_types text/plain text/html 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/*;

}

5 Replies

Looking at this, I assume you simply have to uncomment this bit:

# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 2;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/html text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

How do I do that? Remove '#' ? Thanks for the answer.

It's funny how little had to be done and how much time it cost me. Thank you for your help Nuvini, it seems now its all okay. I didn't know that '#' represents comment.

Heh - yep, # represents comments so they won't be used for the actual config.

For future reference, depending on the type of config, comments can also be in ; - // - - -- or in some cases ''

I even sometimes see REM for comments, and not just in batch files or VB :)

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct