Configuration: HTTP response codes

Origin configuration

The following configuration provides an example of how to configure Unified Origin and two different proxy servers acting as the Origin shield cache.


Unified Origin can be configured to use custom status HTTP status codes. For example for MPEG-DASH output format there are two type of controlled errors: Fmp4MpdFragmentNotFound and Fmp4MpdFragmentNotAvailable. In the following configuration the responses with status code 404 will be send as response when media segment request was not found, and a 204 status code in case the requested fragment is newer than the last fragment available in the DVR window.

# Customize status codes for DASH fragments
<LocationMatch "\.dash$">
  Fmp4MpdFragmentNotFound 404
  Fmp4MpdFragmentNotAvailable 204


More information about each HTTP status codes given by Unified Origin can be found in the Custom HTTP Status codes (Apache) section, and 4XX status codes for Unified Packager in the Status codes section.

Origin shield configuration


Each status code in Nginx needs to be explicitly indicated by ngx_http_proxy_module. This can be achieved by the following two directives:

  • proxy_cache_valid: Sets status codes to cache and its respective time to live in cache.
  • proxy_cache_use_stale: This directive determines the status codes that Origin shield cache will reply with staled cached responses.

In the following Nginx directive configuration we set a TTL of one second to all objects with the following status codes responses. Other status codes such as 200 will use the Cache-Control Headers, otherwise they will not be cached (e.g, 500, 502, 503, 504, etc.).

proxy_cache_valid  300 301 302 307 400 404 405 409 410 412 414 415 1s;
proxy_cache_valid  204 2s;  # Fmp4MpdFragmentNotAvailable: x < Segment duration/2
proxy_cache_valid  403 501 10s; # Forbidden & Not implemented

proxy_cache_use_stale updating;  # Provide stale content while revalidating to the client

Varnish Cache

In Varnish Cache, the following status codes are cached by default:

  • 200: OK
  • 203: Non-Authoritative Information
  • 300: Multiple Choices
  • 301: Moved Permanently
  • 302: Moved Temporarily
  • 307: Temporary Redirect
  • 410: Gone
  • 404: Not Found

The following is an example in VCL on how to cache certain status codes of request responses. It caches all objects with one second of TTL and with exception of status codes 500, 502, 503, and 504. Also, it caches the HLS Master Playlist for one hour of TTL.


It is recommended to cache client error messages (4XX status codes) and server error responses (5XX status codes) with an small TTL. If these type of errors are not cached at all, Varnish Cache will not implement request coalescing for requests going upstream.

sub vcl_backend_response {

    if (beresp.status >= 300 && beresp.status <= 599 )
        if (beresp.status == 403 || beresp.status == 501)
            set beresp.ttl = 10s;
            set beresp.grace = 1s;
            set beresp.ttl = 1s;
            set beresp.grace = 1s;
    elseif (beresp.status == 204)
        # Fmp4MpdFragmentNotAvailable: x < Segment duration/2
        set beresp.ttl = 2s;
        set beresp.grace = 1s;
        std.log("2XX: Use Cache-Control Headers or Expires Headers from backend");