2015-10-21 7 views
6

यदि मैं सही ढंग से समझता हूं तो बेहतर है कि छोटे संसाधनों को gzip न करें क्योंकि वास्तव में CPU पर प्रदर्शन होने पर वे बड़े हो सकते हैं। तो gzip_min_length निर्देश का उपयोग करना इसका एक स्पष्ट समाधान है। हालांकि, एक सर्वर पर यह कोशिश करते समय जो एक आरईएसटी एपीआई चलाता है, मैं इस पर काम कर रहा हूं, काम नहीं कर रहा है। जब मुझे एक खाली जेसन प्रतिक्रिया मिलती है, या बहुत छोटा, सामग्री-एन्कोडिंग हेडर अभी भी मौजूद है और "gzip" पढ़ रहा है।जीजीआईपी न्यूनतम लंबाई निर्देश का सम्मान क्यों नहीं किया जा रहा है?

HTTP Response headers

मेरा प्रश्न क्यों इस सेटिंग nginx द्वारा सम्मानित किया जा रहा है और मैं इसे ठीक करने के लिए क्या कर सकते हैं?

एपीआई Lumen microframework पर बनाया गया है।

मैं Gzip सेटिंग मैं अपने nginx.conf में उपयोग कर रहा हूँ संलग्न किया है:

# Compression 

    # Enable Gzip compressed. 
    gzip on; 

    # Enable compression both for HTTP/1.0 and HTTP/1.1. 
    gzip_http_version 1.1; 

    # Compression level (1-9). 
    # 5 is a perfect compromise between size and cpu usage, offering about 
    # 75% reduction for most ascii files (almost identical to level 9). 
    gzip_comp_level 5; 

    # Don't compress anything that's already small and unlikely to shrink much 
    # if at all (the default is 20 bytes, which is bad as that usually leads to 
    # larger files after gzipping). 
    gzip_min_length 1000; 

    # Compress data even for clients that are connecting to us via proxies, 
    # identified by the "Via" header (required for CloudFront). 
    gzip_proxied  any; 

    # Tell proxies to cache both the gzipped and regular version of a resource 
    # whenever the client's Accept-Encoding capabilities header varies; 
    # Avoids the issue where a non-gzip capable client (which is extremely rare 
    # today) would display gibberish if their proxy gave them the gzipped version. 
    gzip_vary   on; 

    # Compress all output labeled with one of the following MIME-types. 
    gzip_types 
    application/atom+xml 
    application/javascript 
    application/json 
    application/rss+xml 
    application/vnd.ms-fontobject 
    application/x-font-ttf 
    application/x-web-app-manifest+json 
    application/xhtml+xml 
    application/xml 
    font/opentype 
    image/svg+xml 
    image/x-icon 
    text/css 
    text/plain 
    text/x-component; 
    # text/html is always compressed by HttpGzipModule 
+0

क्या आप सुनिश्चित हैं कि यह nginx संपीड़न है और आपका आवेदन नहीं है? –

+0

हां, यकीन है कि ... :-) – Vercoutere

+0

मैं सिर्फ एक ही व्यवहार में पड़ गए और मानते हैं कि यह [nginx gzip मॉड्यूल प्रलेखन] में टिप्पणी (http://nginx.org/en/docs/http की वजह से है /ngx_http_gzip_module.html#gzip_min_length) बताते हुए "लंबाई केवल" सामग्री-लंबाई "प्रतिक्रिया शीर्षलेख फ़ील्ड से निर्धारित होती है।" – cebarth

उत्तर

7

ऊपर मेरी टिप्पणी की पुष्टि इस NGINX gzip module documentation में टिप्पणी करते हुए कहा "लंबाई केवल निर्धारित किया जाता है के अनुरूप प्रतीत होता है "सामग्री-लंबाई" प्रतिक्रिया शीर्षलेख फ़ील्ड से। "

gzip_min_length 1000; के साथ, मेरी JSON प्रतिक्रियाओं gzip'ed किया जा रहा था, भले ही वे केवल 100 बाइट्स थे।

मैंने Content-Length: 100 शीर्षलेख जोड़ने के लिए अपना आवेदन बदल दिया और एनजीआईएनएक्स जीएसआईपी एन्कोडिंग का उपयोग किये बिना JSON प्रतिक्रिया भेजता है।

यदि मैं कॉन्फ़िगरेशन को gzip_min_length 80; पर उसी 100-बाइट सामग्री-लंबाई के साथ बदलता हूं, तो एनजीआईएनएक्स अपेक्षित के रूप में gzip एन्कोडिंग लागू करता है।

लघु कहानी: gzip_min_length चेक को ठीक से संभालने के लिए आपको Content-Length शीर्षलेख NGINX के लिए लागू करने की आवश्यकता है।

संबंधित मुद्दे