How to add header conditional on an upstream_http_ variable in Nginx?

Solution Verified - Updated -

Issue

  • I want to add the Access-Control-Allow-Origin in Nginx only if it's not already set by the upstream.
  • How to add the Strict-Transport-Security header in Nginx if the response is not having the same response header set already?

Environment

  • Red Hat Software Collections (RHSCL)
    • rh-nginx120 (nginx 1.20.1)
    • rh-nginx118 (nginx 1.18.0)
    • rh-nginx116 (nginx 1.16.1)
  • Red Hat Enterprise Linux 8,9 (RHEL) (Application Streams)
    • v1.20
    • v1.18

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content