Share via

Content-Encoding: gzip not preserved through Azure Front Door when caching is disabled

khj 0 Reputation points
2025-09-19T02:26:15.8066667+00:00

Hello,

We are seeing an issue where pre-compressed .gz files served by NGINX are not delivered with the Content-Encoding: gzip header through Azure Front Door (AFD).

[Environment]

  • NGINX origin with gzip_static on;
  • Pre-compressed .gz files exist and serve correctly when accessed directly.
  • AFD configuration:
    • Caching: Disabled -> after solved this problem, we'll enable
    • Compression: Disabled
  • Domains:
    • Production: static.site.co.kr (AFD)
    • Origin: www.site.co.kr

[Observed Behavior]

  1. Direct NGINX access
    curl -I -H "Accept-Encoding: gzip" https://www.site.co.kr/_next/static/chunks/main.js
  • Content-Encoding: gzip is present.
  1. AFD endpoint
    curl -I -H "Accept-Encoding: gzip" https://static.site.co.kr/_next/static/chunks/main.js
  • Content-Encoding: gzip is missing.
  • X-Cache: CONFIG_NOCACHE indicates the request hits the origin.

It seems that there is no issue with the NGINX configuration, so why is this behavior occurring?

Azure Front Door
Azure Front Door

An Azure service that provides a cloud content delivery network with threat protection.


2 answers

Sort by: Most helpful
  1. Anonymous
    2025-09-19T07:01:20.82+00:00

    Hi khj,

    Thank you for reaching out on Microsoft Q&A forum.

    We came across some of the findings which may be the causes of error & can be verified by your end

    AFD Compression Disabled: Since compression is disabled in AFD, it does not add or preserve the Content-Encoding header unless explicitly configured to do so.

    Pre-compressed Files with gzip_static: NGINX serves .gz files correctly when gzip_static on is set. However, AFD may strip or fail to forward the Content-Encoding header

    It happens because

    1. The origin uses chunked transfer encoding.
    2. The request lacks a valid Accept-Encoding header.
    3. The file type is not eligible for compression under AFD rules

    To ensure .gz files are served with the correct Content-Encoding: gzip header through AFD, we can try some of the fixes below

    Enable Compression in AFD

    Go to Azure Portal > Front Door > Routes.

    Enable compression for the route serving static files.

    Wait up to 10 minutes for propagation.

    1. Use Rules Engine to Preserve Headers

    Create a rule to preserve Accept-Encoding and forward Content-Encoding.

    Ensure the rule applies to requests with .gz extensions or specific paths like /static/.

    1. Avoid Chunked Transfer Encoding

    Ensure NGINX is not using chunked encoding for .gz files.

    Pre-compressed files should have a known Content-Length to avoid chunked responses.

    If you find this comment helpful, please “up-vote” for the information provided , this can be beneficial to community members.

    Kindly let us know if you have any additional questions

    Thanks

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

  2. Anonymous
    2025-09-26T07:58:17.9366667+00:00

    Hi Khj,

    Sorry for the delayed response

    Please try to execute below steps

    1. Use Rules Engine to Explicitly Preserve Headers
      • As you mentioned in above comment not yet tested Rules Engine changes, though AFD should forward headers by default, explicitly configuring Rules Engine to preserve Content-Encoding and Content-Length can help avoid unexpected behavior.
    2. Enable Caching on AFD (if feasible)
      • Caching helps AFD preserve headers like Content-Encoding. If caching is disabled, AFD may strip or ignore these headers.

    Hope you find my above comment helpful, if yes, please “up-vote” for the information provided ,this can be beneficial to community members.

    Kindly let us know if you have any additional questions

    Thanks

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.