Enable gzip compression for nginx in css/js

Source: Internet
Author: User
Tags curl

Adam is the topic of Ghost in the last two days. My blog is running on servers outside China, so to speed up access, enabling gzip compression is essential.

Vim/etc/nginx. conf

Find the code similar to the following:

Gzip on
Gzip_types text/plain

Just change it to the following:

Gzip on;
Gzip_buffers 4 16 k;
# Gzip_http_version 1.1;
Gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/javascript;
Gzip_comp_level 6;
Gzip_vary on;
Gzip_disable "MSIE ";
Gzip_proxied any;

You can use curl for testing, for example:

Curl-I-H "Accept-Encoding: gzip, deflate" "/assets/js/script. js"

Return

HTTP/1.1 200 OK
Server: nginx/1.0.15
Date: Tue, 01 Jul 2014 17:25:14 GMT
Content-Type: application/javascript
Connection: keep-alive
Vary: Accept-Encoding
X-Powered-By: Express
ETag: "24792-1404232049000"
Cache-Control: public, max-age = 3600
Last-Modified: Tue, 01 Jul 2014 16:27:29 GMT
Content-Encoding: gzip
You can see that Content-Encoding: gzip is enabled.
If not, check whether the type in/etc/nginx/mime. types corresponds to gzip_types in nginx. conf.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.