In example we use ubuntu 16.04.
Edit your /etc/nginx/nginx.conf
1 2 3 4 5 6 7 8 9 10 11 12 | http { ... ## # Gzip Settings ## gzip on; gzip_comp_level 9; gzip_types *; gzip_vary on; } |
Reference:
– gzip, to enable or disable.
– gzip_comp_level, compression level 1 to 9. Higher compression will make server slower, but response page size smaller.
– gzip_types, compression for specific MIME types.
– gzip_vary, to show Accept-Encoding gzip.
Edit /etc/nginx/sites-availaible/foodpalate.com.au.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | server { ... # Media: images, icons, video, audio, HTC location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ { access_log off; add_header Cache-Control "public"; expires 1M; } # CSS and Javascript location ~* \.(?:css|js)$ { access_log off; add_header Cache-Control "public"; expires 1y; } } |
– Set media expired 1 month.
– Set css, js expired in 1 year.
This screenshoot before
And after optimize